Move a control at run time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mihail
    Contributor
    • Apr 2011
    • 759

    Move a control at run time

    Hello !
    I wish to move a control (a label or a shape) by dragging it with the mouse And/Or (I prefer to be And) with arrows keys at run time.
    Can you point me to the right direction ?

    Thank you !
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This will place a "Size" cursor and drag the command.

    Code:
    Dim MOUSEdownX As Integer
    Dim MOUSEdownY As Integer
    
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       MOUSEdownX = X
       MOUSEdownY = Y
       Command1.MousePointer = vbSizePointer
    End Sub
    
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If Button = vbLeftButton Then
          With Command1
             .Left = .Left - MOUSEdownX + X
             .Top = .Top - MOUSEdownY + Y
          End With
       End If
    End Sub
    
    Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Command1.MousePointer = vbDefault
    End Sub

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      Thank you, Guido !
      I don't try yet but I think that your code will do the job by using the mouse.

      I think I know now how to move the control using keyboards too.
      Thank you again !

      Comment

      Working...