VBE controls on form moving with arrows

Hello, everybody!

Visual Basic Editor problem:

Is there a way to make the controls on the userform moveable with the arrow keys?

Greetings!
Parents
No Data
Reply
  • So easy
    Create UserForm1 with Label1
    Put into Userform module next code:


    Dim prevX As Single, prevY As Single
    Private Sub Label1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        prevX = X
        prevY = Y
    End Sub

    Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        If Button = 1 Then
            Label1.Left = Label1.Left + (X - prevX)
            Label1.Top = Label1.Top + (Y - prevY)
        End If
    End Sub

    Arrow buttons can be tied similarly

    Regards,
    Taras

Children