我有一个 bresenham 算法,我在 Line 类中写了它 我可以画线 现在我想绘制多边形,所以我写了它的函数(void Polygon) 我应该将每次点击的坐标存储在一个数组中,然后我的函数应该得到它们我不'不知道如何存储每次点击
Radiobutton1 用于绘制线,radiobutton2 用于绘制多边形
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));
}