在VB6中移动按钮

时间:2011-11-14 17:55:59

标签: vb6

在visual basic中是否可以使用鼠标拖动来移动按钮,该按钮位于同一水平线上并且每次只移动一定距离。类似于计算机声音的平衡控制

1 个答案:

答案 0 :(得分:4)

这是一个拖动名为Command1的按钮的简单示例。要限制它可以移动的距离,只需向DragOver事件添加一些条件:

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