-1

我有一个 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));
      }
4

1 回答 1

1

您可以点一下点击坐标:

Point p = new Point(e.x, e.y);

将您获得的积分保存在列表中:

// Declaration:
List<Point> myPoints = new List<Point>();

// in the method: 
if (radioButton2.Checked) {
   myPoints.Add(new Point(e.x, e.y));
}

数组不是一个好主意,因为您通常不知道会有多少点击。List 是可变长度的,因此在这种情况下很有用。

于 2012-05-13T11:58:01.697 回答