I Have a bresenham algorithm which I wrote it in class Line
I Can draw lines Now I wanted to draw polygons so I wrote it’s function(void Polygon)
I should store coordinates of each click in an array and then my function should get them
I don’t know how to store each click
Radiobutton1 is for draw line and radiobutton2 is for drawing polygons
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
if(radioButton1.Checked)
if (firstClick)
{
firstX = e.X;
firstY = e.Y;
firstClick = false;
}
else
{
Line l = new Line(firstX, firstY, e.X, e.Y, panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text));
firstClick = true;
}
if(radioButton2.Checked)
{
//how to write here so as to store each click in array
}
}
private void button1_Click(object sender, EventArgs e)
{
int n = Convert.ToInt32(textBox2.Text);
Polygon(n, coor);
}
void Polygon(int n,int[] coordinates)
{
if(n>=2)
{
Line l=new Line(coordinates[0],coordinates[1],coordinates[2],coordinates[3],panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text));
for(int count=1;count<(n-1);count++)
l=new Line(coordinates[(count*2)],coordinates[((count*2)+1)],coordinates[((count+1)*2)],coordinates[(((count+1)*2)+1)],panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text));
}
You can make a point of the click coordinates:
Save the points you get in a List:
An array will not be a good idea, because you normally don’t have any idea how many clicks there will be. A List is of variable length, so it’s useful in this situation.