简体   繁体   English

WPF:如何知道用户是否单击了在Canvas中绘制的矩形/直线/椭圆形?

[英]WPF: How to know if users clicked a Rectangle/Line/Ellipse which are drawn in Canvas?

I'm doing MyPaint application. 我正在做MyPaint应用程序。 Now I have some problem. 现在我有一些问题。

  1. Users draw some shapes in canvas. 用户在画布上绘制一些形状。 Then they can select and move it by click-drag and drop . 然后,他们可以通过单击和拖放来选择和移动它。 So how to know if users clicked on a shapes (Outline or within the shapes)? 那么如何知道用户是否单击了形状(轮廓或形状内)?
  2. As soon as they clicked on the shapes, a dash-stroke square and some anchor points will be shown (as the Picture ). 当他们点击的形状,破折号冲程广场和一些锚点将显示(如照片 )。 Then users can click and keep pressing on those anchor point to resize the shapes. 然后,用户可以单击并按住这些锚点以调整形状的大小 So how to design Resize function like this ? 那么如何设计这样的Resize函数呢?

I have no idea about the code. 我对代码一无所知。 Can anyone give me some hints? 谁能给我一些提示吗? Thanks in advance 提前致谢

Finding out if the user has clicked on the shape could be as easy as implementing a MouseDown event handler on the shape (rectangle.MouseDown += ...). 找出用户是否点击了形状就像在形状上实现MouseDown事件处理程序一样容易(rectangle.MouseDown + = ...)。 As far as moving and resizing, this example should be useful (you may have to calculate your own scale if you're only using the mouse but it should point you in the right direction): https://msdn.microsoft.com/en-us/library/vstudio/ee649090(v=vs.100).aspx 就移动和调整大小而言,此示例应该很有用(如果您仅使用鼠标,则可能必须计算自己的比例,但它应将您指向正确的方向): https : //msdn.microsoft.com/ zh-CN / library / vstudio / ee649090(v = vs.100).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM