如何找到多边形的坐标点? [英] how to find the coordinate points of polygon?

查看:114
本文介绍了如何找到多边形的坐标点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中我试图绘制多边形我需要找到多边形的坐标点并显示该坐标指向文本框。可以任何人帮我弄清楚...



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));
           }
           }</point></point>

推荐答案

您已经有了坐标:它们位于积分集合。

所以你需要做的就是将每个Point转换成一个字符串,并显示它 - 但我不会使用TextBoxes,因为有一个变量号积分,取决于用户点击的次数 - 以及每个人是否需要一个文本框... yuck。



更好的解决方案是使用单个多行文本框或datagridview。后者很简单:

You have your coordinates already: they are in the points collection.
So all you need to do is convert each Point to a string, and display it - but I wouldn't use TextBoxes, because there are a variable number of Points, depending on how many times the user clicks - and if each one needs a textbox... yuck.

A better solution is to use a single multiline textbox, or a datagridview. The later is simple:
myDdataGridView.DataSource = null;
myDataGridView.DataSource = points;

系统将为您整理显示。 (您需要第一行刷新DataGridView)

The system will sort out the display for you. (You need the first line to "refresh" the DataGridView)


解决方案非常简单,因为您已经在该代码片段中编写了解决方案,除非我遗漏了您所避开的内容解释。



在这里,你这样做的地方:

The solution is so simple because you have practically written the solution in that code snippet already, unless I am missing something that you haven't explained.

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





你不能只创建一个名为的函数UpdateTextbox(),像这样?



Can't you just create a function called UpdateTextbox(), like this?

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



您可以自定义代表coodinates的方式,但实际上这段代码与您已经完全不同。 points 是全局定义的,因此您可以在此函数中使用它。您需要做的就是在适当的时候调用 UpdateTextbox(),比如 pictureBox1_MouseDown


You can customize the way that you represent the coodinates, but really this code is not that different from what you have already. points is defined globally, so you can use it in this function. All you need to do is call UpdateTextbox() at an appropriate moment, say in pictureBox1_MouseDown.


这篇关于如何找到多边形的坐标点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆