【问题标题】:C# working with drawn polygonsC# 处理绘制的多边形
【发布时间】:2013-07-10 07:38:44
【问题描述】:

我有两个关于多边形的问题。

  1. 我正在将多边形绘制到图片框。图片框有滑动条。如果我使用滑动条向上或向下移动,则会删除当前不可见的多边形。我使用 C# 才 2 个月,所以我还是新手。如何解决这个问题?

  2. 是否可以单击多边形并用鼠标移动它们或更改它们的大小?

最好的问候

for (int i = 0; i < final_rng.Count; i++) 
{
    listPoint.Clear(); 
    for (int j = 0; j < final_rng[i].body.Count; j++)
    { 
       listPoint.Add(new Point(final_rng[i].body[j].X, final_rng[i].body[j].Y)); 
     }
//for (int j = 0; j < final_rng[i].body.Count; j++)
    grafika.FillPolygon(Brushes.Turquoise, listPoint.ToArray()); }
//for (int i = 0; i < final_rng.Count; i++)

【问题讨论】:

  • 这取决于您如何存储您的绘图图元,如果您只是将它们绘制到屏幕上,那么一旦它们超出范围就会丢失它们
  • 好的,所以我有这个代码 for (int i = 0; i grafika.FillPolygon(Brushes.Turquoise, listPoint.ToArray()); }//for (int i = 0; i

标签: c# drawing editing polygons


【解决方案1】:

如果您直接在PictureBox 上绘制,则在重新绘制控件时(例如,当您调整窗口大小时),绘制的多边形将丢失。更好的方法是在Bitmap 上绘制并添加,然后将其显示在PictureBox 中。一个例子:

// A new bitmap with the same size as the PictureBox
var bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);

//Get the graphics objectm which we can use to draw
var graphics = Graphics.FromImage(bitmap);

//Draw stuff
graphics.FillRectangle(Brushes.Red, new Rectangle(0, 0, 500, 500));

//Show the bitmap with graphics image in the PictureBox
pictureBox1.Image = bitmap;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多