In my code I am trying to draw polygon I need to find coordinate points of polygon and display that coordinate points in to text boxes. Can anybody help me to figure it out?
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));
}
}
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.