如何找到多边形的坐标点?

时间:2014-05-03 06:05:18

标签: c# winforms

在我的代码中我试图绘制多边形我需要找到多边形的坐标点并显示该坐标指向文本框。任何人都可以帮我解决一下吗?

List<Point> points = new List<Point>();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    //points.Clear();
    // points.Push(e.Location);

    if (e.Button == MouseButtons.Left)
    {
        points.Add(e.Location);

        pictureBox1.Invalidate();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        if (points.Count > 1)
            e.Graphics.DrawPolygon(Pens.DarkBlue, points.ToArray());

        foreach (Point p in points)
        {
            e.Graphics.FillEllipse(Brushes.Red,
                                   new Rectangle(p.X - 2, p.Y - 2, 4, 4));
        }
    }

1 个答案:

答案 0 :(得分:0)

    List<Point> points = new List<Point>();
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
       if (e.Button == MouseButtons.Left)
   {
      points.Add(e.Location);

      pictureBox1.Invalidate();
       dataGridView1.DataSource = null;
        dataGridView1.DataSource = points;
          UpdateTextbox();
    }
    }

       private void pictureBox1_Paint(object sender, PaintEventArgs e)
   {
       if (points.Count > 1)
        e.Graphics.DrawPolygon(Pens.DarkBlue, points.ToArray());

       foreach (Point p in points)
      {
        e.Graphics.FillEllipse(Brushes.Red,
        new Rectangle(p.X - 2, p.Y - 2, 4, 4));
      }
      }


        void UpdateTextbox()
           {
        textBox1.Text = "";
        foreach (Point p in points)
        {
            textBox1.Text += (p) + "\n".ToString();
        }
    }