我如何像在绘画中通过拖动鼠标一样在WPF中绘制矩形和圆形/椭圆形 [英] how can I draw a rectangle and circle/ellipse in WPF like we do in paint by dragging mouse

查看:848
本文介绍了我如何像在绘画中通过拖动鼠标一样在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.


这篇关于我如何像在绘画中通过拖动鼠标一样在WPF中绘制矩形和圆形/椭圆形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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