-1

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.

SezMe
  • 527
  • 8
  • 24
  • 1
    That question is using a Windows Forms project (also available in VB.NET), but based on your most used tags I guess you're using WPF? If this is the case, the equivalent to WinForms's `Control.Location` property is [`Control.Margin`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.margin?view=netframework-4.8#System_Windows_FrameworkElement_Margin) (top and left, specifically) in WPF, and the equivalent to `Update` is `InvalidateVisual` (although there is no need to call either in this case, so you can just ignore it). – Visual Vincent Oct 29 '19 at 19:34
  • 1
    For future reference, Windows Forms (WinForms) is the first of the two technologies that can be used to create standard, close to native Windows applications. It is based on Win32 and renders most of its content using your CPU. || Windows Presentation Foundation (WPF) is the second of the two, which came along afterwards and is more of a specialized technology that uses DirectX (and therefore your GPU) to render its content. – Visual Vincent Oct 29 '19 at 19:39
  • @VisualVincent Yes, I should have added "wpf" which I just did. I'll try margin. – SezMe Oct 30 '19 at 16:05
  • @VisualVincent If you post you first reply as an answer, I'll mark it as having answered my question. – SezMe Oct 30 '19 at 16:30
  • Glad I could help, and sorry for the late reply. – Visual Vincent Nov 01 '19 at 18:31

2 Answers2

1

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.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
0

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
Seby_Plays
  • 26
  • 5
  • Welcome to Stack Overflow! Your answer applies only to WinForms, but like the tags indicate the OP is using WPF. These are two different GUI technologies that only share a few similarities. In either case, please make sure to read through the entire question thorougly before answering, as the OP explicitly stated that `Control.Location` (which refers to the same property as `Me.Location`) doesn't exist. Thank you! – Visual Vincent Nov 07 '19 at 17:07