Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Form - drag control (Excel 2003)

    Hi all

    I have a form that I would like to be able to drag a labelcontrol with a mouse around a userform. Can someone suggest a thread?

    Thanks,
    Darryl.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form - drag control (Excel 2003)

    You can use the MouseDown, MouseMove and MouseUp events of the label. Here is a simple example for a label imaginatively named Label1:

    Private blnDragging As Boolean

    Private Sub Label1_MouseDown( _
    ByVal Button As Integer, _
    ByVal Shift As Integer, _
    ByVal X As Single, _
    ByVal Y As Single)
    blnDragging = True
    End Sub

    Private Sub Label1_MouseMove( _
    ByVal Button As Integer, _
    ByVal Shift As Integer, _
    ByVal X As Single, _
    ByVal Y As Single)
    If blnDragging Then
    Me.Label1.Left = Me.Label1.Left + X
    Me.Label1.Top = Me.Label1.Top + Y
    End If
    End Sub

    Private Sub Label1_MouseUp( _
    ByVal Button As Integer, _
    ByVal Shift As Integer, _
    ByVal X As Single, _
    ByVal Y As Single)
    blnDragging = False
    End Sub

    See attached example.

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Form - drag control (Excel 2003)

    Thanks Hans.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •