"dave" <da********@blueyonder.co.uk> wrote in message
news:rG*************@news-binary.blueyonder.co.uk...
Hi
How do i drag and drop a command button using the mouse in runtime?
Its driving me mad
I am using Visual Basic 6
Thanx Dave
You could also try manually coded dragging. You can restrict the motion
to left-right by changing only the .Left property, or to up-down by
changing only the .Top.
Option Explicit
Dim mMoving As Boolean
Dim mStartX As Single
Dim mStartY As Single
Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'control left click to drag
If Button = vbLeftButton And Shift = vbCtrlMask Then
mMoving = True
mStartX = X
mStartY = Y
End If
End Sub
Private Sub command1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim xNew As Single
Dim yNew As Single
If mMoving Then
With Command1
xNew = .Left + X - mStartX
yNew = .Top + Y - mStartY
If xNew >= 0 And xNew + .Width <= Me.ScaleWidth Then
.Left = xNew
End If
If yNew >= 0 And yNew + .Height <= Me.ScaleHeight Then
.Top = yNew
End If
End With
End If
End Sub
Private Sub command1_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
mMoving = False
End Sub