我如何像在绘画中通过拖动鼠标一样在WPF中绘制矩形和圆形/椭圆形
问题描述:
我正在WPF中开发白板应用程序.
如何像在画图"中一样通过拖动鼠标指针来拖动鼠标来绘制矩形和圆形/椭圆形?
我正在使用WPF画布进行绘制.
P.S. :我已经引用了此文章,但是它太复杂了,我是无法理解.
I am developing a whiteboard application in WPF.
How can I draw a rectangle and circle/ellipse by dragging the mouse like we do in Paint by dragging the mouse pointer ?
I am using WPF canvas for drawing.
P.S. : I have refered this article, but it''s too complex, i am not able to understand.
答
此处是一篇基础文章,可帮助您弄清楚如何绘制这些形状:
http://msdn.microsoft.com/en-us/library/ms747393.aspx [ ^ ]
要使用鼠标绘制它们,只需在鼠标指针的坐标处(将其设置为要绘制的对象的一个角)在鼠标下方开始绘制即可.然后将另一组坐标设置为鼠标指针的当前位置(并在其移动时保持更新).当发生鼠标上移事件时,将另一组坐标最终确定为鼠标指针的当前位置.这样,您可以轻松地单击并拖出一个框,椭圆,圆等.
顺便问一下,这是家庭作业吗?我记得为我的一个班级做了一个这样的应用程序.
Here is a basic article that will help you figure out how to draw these shapes:
http://msdn.microsoft.com/en-us/library/ms747393.aspx[^]
To draw them using the mouse, just start the drawing on mouse down at the coordinates of the mouse pointer (set that as one corner of the object being drawn). Then set the other set of coordinates as the current location of the mouse pointer (and keep updating it as it moves). When the mouse up event occurs, finalize the other set of coordinates as the current location of the mouse pointer. This way you can click and drag out a box, ellipse, circle, etc. easily.
By the way, is this homework? I remember doing an application like this for one of my classes.