vb在窗体中,按钮可以拖动,放下鼠标按钮就放在那里,怎么实现?

谢谢!
2024-12-20 02:27:08
推荐回答(4个)
回答1:

***版本一***左键单击后可以移动,再次单击停止移动:

Dim bMove As Boolean '判断可不可以移动
Dim oldX!, oldY! '!是Single的缩写

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Command1.Left = Command1.Left - oldX + X
Command1.Top = Command1.Top - oldY + Y
End If
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '1就是鼠标左键
bMove = Not bMove
oldX = X
oldY = Y
End If
End Sub

***版本二***左键按下时可以拖动:

Dim oldX!, oldY! '!是Single的缩写

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '1就是鼠标左键
oldX = X
oldY = Y
End If
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Command1.Left = Command1.Left - oldX + X
Command1.Top = Command1.Top - oldY + Y
End If
End Sub

回答2:

在按钮的鼠标按下事件里写...if button = 1 then if 按钮.Eanble = True then 按钮.Eanble = False 按钮.Left = X: 按钮.Top = Y else 按钮.Eanble = True end ifend if

回答3:

SendMessageA(按钮的句柄,161.2.0)这个事API命令,在易语言里直接按钮.发送信息(161.2.0)就可以实现的。

回答4:

如果,怎样~