Reputation: 393
Is it possible in visual basic to have a button that you can move with a mouse drag, which stays on the same horizontal line and only moves a certain distance each way. Something like the balance control on the sound for a computer
Upvotes: 0
Views: 1359
Reputation: 11263
Here's a simple example to drag a button named Command1. To limit the distance it can move, just add some conditions to the DragOver event:
Dim blnDrag As Boolean
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not blnDrag Then
blnDrag = True
Command1.Drag
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.DragMode = vbnone
blnDrag = False
End Sub
Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Command1.Left = X
End Sub
Private Sub Form_Load()
Command1.DragMode = vbManual
End Sub
Upvotes: 4