vb在窗体中,按钮可以拖动,放下鼠标按钮就放在那里,怎么实现?
答案:4 悬赏:30 手机版
解决时间 2021-01-09 08:02
- 提问者网友:龅牙恐龙妹
- 2021-01-08 22:51
vb在窗体中,按钮可以拖动,放下鼠标按钮就放在那里,怎么实现?
最佳答案
- 五星知识达人网友:拾荒鲤
- 2021-01-08 23:03
***版本一***左键单击后可以移动,再次单击停止移动:
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
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
全部回答
- 1楼网友:执傲
- 2021-01-09 00:34
如果,怎样~
- 2楼网友:千夜
- 2021-01-08 23:35
SendMessageA(按钮的句柄,161.2.0)这个事API命令,在易语言里直接按钮.发送信息(161.2.0)就可以实现的。
- 3楼网友:胯下狙击手
- 2021-01-08 23:10
在按钮的鼠标按下事件里写...if button = 1 then if 按钮.Eanble = True then 按钮.Eanble = False 按钮.Left = X: 按钮.Top = Y else 按钮.Eanble = True end ifend if
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯