Windows窗体中的WPF行的等效项 [英] Equivalente of WPF Line in Windows Forms

查看:127
本文介绍了Windows窗体中的WPF行的等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在wpf中有一个名为Line的控件,Line line = new Line(); ...

In wpf have a control called Line, Line line = new Line(); ...

推荐答案

System.Windows.Forms 中没有这些图形基元作为对象。您可以根据类 System.Drawing.Graphics 提供的图形渲染方法创建它们。请参阅:

http://msdn.microsoft.com /en-us/library/system.drawing.graphics.aspx [ ^ ]。



您可以在任何 Control <上使用此类渲染图形/ code>,包括表格。您需要覆盖虚方法 System.Windows.Forms.Control.OnPaint 或处理事件 System.Windows.Forms.Control.Paint 并使用传递给此方法的 System.Drawing.Graphics 实例作为参数:

< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint.aspx> http://msdn.microsoft.com/en-us/library/system .windows.forms.control.onpaint.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx [ ^ ]。



请参阅我过去的答案以获得进一步的建议:

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

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

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

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

在图片框中附加图片 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

如何从旧图纸中清除面板 [ ^ ]。



另请参阅此文章,解释它如何映射到原始Windows API :在C#.net鼠标滚轮中缩放图像 [ ^ ],

MFC绘制的线条消失了 [ ^ ]。





There are no those graphical primitives as objects in System.Windows.Forms. You can create them based on the graphic rendering methods provided by the class System.Drawing.Graphics. Please see:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

You can render graphics using this class on any Control, including Form. You need to override the virtual method System.Windows.Forms.Control.OnPaint or handle the event System.Windows.Forms.Control.Paint and use the instance of System.Drawing.Graphics passed to this method or to your event handler as a parameter:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx[^].

Please see my past answers for further advice:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^],
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

See also this one, explaining how it's mapped to raw Windows API: Zoom image in C# .net mouse wheel[^],
MFC Drawed lines is disappeared[^].


会员10267665写道:
Member 10267665 wrote:

它是不同的,因为我不能在它上面分配一个事件,例如,我需要一个可以在我点击它时引发事件的行。

It's different, because i can't assign an event on it for example, i need a line that can raise events when i click on it.

你必须处理点击和其他输入事件控制在哪里渲染线条或其他元素。这是您处理事件的控件 Paint 或覆盖方法 OnPaint



如果是单击处理,则需要覆盖虚拟方法 System.Windows.Forms.Control.OnClick 或处理事件 System.Windows.Forms.Control.Click

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onclick.aspx [ ^ ],

http://msdn.microsoft.com/ en-us / library / system.windows.forms.control.click.aspx [ ^ ]。



但是n,硬件开始:您需要计算一些可接受的 near 线点,这些线点将用作热区,其中点击与线对象相关联。在你的点击处理程序中,你必须确定点击坐标是否命中了这个附近区域(所谓的命中测试),并根据该标准继续进行与线相关的处理,或处理其他一些图形对象,或忽略该事件。涉及一些数学。



-SA

You have to handle click and other input events on the control where you render you lines or other elements. This is the control on which you handle the event Paint or override the method OnPaint.

In case of click handling, you will need to override the virtual method System.Windows.Forms.Control.OnClick or handle the event System.Windows.Forms.Control.Click:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onclick.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.click.aspx[^].

But then, the hard part starts: you would need to calculate some acceptable vicinity of the line points which you would use as a "hot area" where the click is associated with your line object. In you handler of the click, you will have to determine if the click coordinates hit the area of this vicinity (so called "hit test") and, depending on that criterion, proceed with line-related handling, or handle some other graphical object, or ignore the event. Some mathematics is involved.

—SA


这篇关于Windows窗体中的WPF行的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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