如何在控件上绘制线条 [英] how to draw lines on a control

查看:84
本文介绍了如何在控件上绘制线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个控制面板,并包含不同的picturbox来显示控件上的图片。这些picturbox也可以使用多线程移动。我想要画出每张照片的移动路径。请。

请给我任何建议。

代码如下。 agentbox是picturbox; ratimage是每个图片框的位图图片。

Hi ,

i have a control panel, and contains different picturbox to display pictures on the control. these picturboxs also moveable using Multithreading. i want that to draw the path of movement of each picture. please.
any suggestion please.
code is given below. agentbox is picturbox; ratimage is bitmap image for each picturebox.

}
 Graphics g = Graphics.FromImage(ratImage);
               Pen pColor = new Pen(Color .Black );
               pColor.Width = 3;
               Brush bb = pColor.Brush;
               g.FillEllipse(bb, new Rectangle(new Point(agentBox.Width / 2, agentBox.Height / 2), new Size(20, 20)));
               

               this.agentBox.Image = ratImage;
               this.agentBox.SizeMode = PictureBoxSizeMode.StretchImage;
               
    
               agentBox.Left = p.X;
               agentBox.Top = p.Y;               
               
               


               Graphics gControlPanle = panel101.CreateGraphics();
               GraphicsPath agentPath = new GraphicsPath();
               
                   agentPath.AddLine(this.fromPoint , this.toPoint );
                   agentPath.FillMode = FillMode.Winding;
                  

                   gControlPanle.DrawPath(pColor, agentPath);
}

推荐答案

如果你想绘制控件,为什么要画一个位图(当然你可以do)?



你的主要错误是使用 CreateGraphics 。当然,您也可以这样做,但这不是您想要的,可以成功获得动画,交互式甚至静态图形。您需要使用 System.Drawing.Graphics 的实例传递给方法 System.Windows.Forms.Control.OnPaint 您可以覆盖事件 System.Windows.Forms.Control.Paint 的事件句柄。有关详细信息,请参阅我过去的答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



对于某些人来说更高级的主题,如图形线程,请参阅这两个:

何w加速我的vb.net应用程序? [ ^ ],

在C#.net鼠标滚轮中缩放图像 [ ^ ]。



-SA
If you want to draw on control, why would you draw on a bitmap (which of course you can do)?

You main mistake is using CreateGraphics. Of course, you can do it, too, but this is not what you want, to successfully get animated, interactive, or even static graphics. You need to use instance of System.Drawing.Graphics passed to the method System.Windows.Forms.Control.OnPaint you can override, or, alternatively to your event handle of the event System.Windows.Forms.Control.Paint. For further detail, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

For some a bit more advanced topics, such as threading with graphics, please see also these two:
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

—SA


这篇关于如何在控件上绘制线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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