简体   繁体   English

在VB中通过鼠标拖动来移动控件

[英]Moving a control by dragging it with the mouse in VB

In the final answer in this post , Paweł Wojda posts a general way to move controls with a mouse.这篇文章的最终答案中,Paweł Wojda 发布了一种使用鼠标移动控件的一般方法。 However, I'm working in VB and have been unable to translate his approach because there are no equivalents to control.location and control.update.但是,我在 VB 中工作并且无法翻译他的方法,因为没有 control.location 和 control.update 的等价物。 How can this same functionality be ported to VB.如何将相同的功能移植到 VB。

The question you linked is using a Windows Forms project, however based on your most used tags I guess you're using WPF.您链接的问题是使用 Windows Forms 项目,但是根据您最常用的标签,我猜您使用的是 WPF。

The equivalent to WinForms's Control.Location property is Control.Margin in WPF (top and left, specifically).与 WinForms 的Control.Location属性等效的是 WPF 中的Control.Margin (特别是顶部和左侧)。

The, somewhat, equivalent to Control.Update is Control.InvalidateVisual .在某种程度上,与Control.Update等效的是Control.InvalidateVisual Although, in this case there is no need to call either, so you can just ignore it.虽然,在这种情况下也不需要调用,所以你可以忽略它。

dim down as new boolean On mouse down event: dim down as new boolean在鼠标按下事件:

Down = true

On mouse up event:在鼠标向上事件:

Down =false

On mouse move event:鼠标移动事件:

If down = true Then
      Me.location = cursor.position
 End if

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

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