Sorry if this sounds a bit of a dim question - I'm completely new to this. I'm trying to get a new ellipse to appear on each tick of a timer. So far, I have:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
private Bitmap DrawingArea;
int numberofcircles = 0;
int[] narrary = new int[30];
int newcircle;
Random rnd = new Random();
public Form1()
{
InitializeComponent();
Invalidate();
}
private void button1_Click(object sender, EventArgs e)
{
numberofcircles = numberofcircles + 1;
newcircle = (rnd.Next(15) * 6) + 76;
narrary[numberofcircles] = newcircle;
Invalidate();
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
DrawingArea = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Pen pen = new Pen(Color.Black);
using (var canvas = Graphics.FromImage(DrawingArea))
{ canvas.Clear(Color.Transparent);
canvas.DrawLine(pen, 100, 100, 700, 100);
for (int i = 1; i <= numberofcircles; i++)
{
canvas.DrawEllipse(pen, 180 + (30 * i), narrary[i], 8, 6);
}
}
this.Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Color.Red);
for (int i = 1; i <= numberofcircles; i++)
{
canvas.DrawEllipse(pen, 180 + (30 * i), narrary[i], 8, 6);
}
e.Graphics.DrawImage(DrawingArea, 0, 0, DrawingArea.Width, DrawingArea.Height);
}
private void timer1_Tick(object sender, EventArgs e)
{
numberofcircles = numberofcircles + 1;
newcircle = (rnd.Next(15) * 6) + 76;
narrary[numberofcircles] = newcircle;
for (int i = 1; i <= numberofcircles; i++)
{
canvas.DrawEllipse(pen, 180 + (30 * i), narrary[i], 8, 6);
}
Invalidate();
}
}
}
"canvas" and "pen" references are flagging up as errors in the Form1_Paint and timer1_Tick sections ("The name 'canvas' does not exist in the current context"). I'm sure I must be referencing them wrong, but I'm afraid I don't have the basic C# knowledge to be able to sort this out!
I'd be very grateful for any help.