如何在WPF中使用鼠标在运行时调整大小和移动图像 [英] How to resize and move image at run time using mouse in WPF

查看:105
本文介绍了如何在WPF中使用鼠标在运行时调整大小和移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想使用WPF中的鼠标拖动选项来调整大小和移动图像控件.如果您知道,请帮助我.

Hi,
I want to resize and move a image control using the mouse drag option in WPF. If you knows please help me.

推荐答案

这很简单.对于图像控件的父级,请使用类 System.Windows.Controls.Canvas的实例.处理移动控件实例的事件MouseDownMouseUpMouseMove.要修改位置,请对移动对象的画布实例的附加属性进行修改.这就像使用方法Canvas.SetLeft(UIElement element, double length)Canvas.SetTop(UIElement element, double length)之类的方法一样简单,其中element是您要移动的控件:
http://msdn.microsoft.com/en-us/library/system. windows.controls.canvas.aspx [ ^ ].

其他所有内容只是代码的纯逻辑.

另请参阅此附加属性概述,以了解其工作原理:
http://msdn.microsoft.com/en-us/library/ms749011.aspx [ ^ ].

—SA
This is simple enough. For a image control''s parent, use the instance of the class System.Windows.Controls.Canvas. Handle the events MouseDown, MouseUp and MouseMove of the instance of your moving control. For modification of location, use the modification of an attached property of the instance of the canvas for your moving object. This is as simple as using the methods Canvas.SetLeft(UIElement element, double length), Canvas.SetTop(UIElement element, double length) and the like, where element is your control you want to move:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[^].

Everything else is just pure logic of your code.

See also this overview on attached properties, to understand how it works:
http://msdn.microsoft.com/en-us/library/ms749011.aspx[^].

—SA


这篇关于如何在WPF中使用鼠标在运行时调整大小和移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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