简体   繁体   中英

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. 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. How can this same functionality be ported to VB.

The question you linked is using a Windows Forms project, however based on your most used tags I guess you're using WPF.

The equivalent to WinForms's Control.Location property is Control.Margin in WPF (top and left, specifically).

The, somewhat, equivalent to Control.Update is 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:

Down = true

On mouse up event:

Down =false

On mouse move event:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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