设计一个移动窗体的vb程序。在窗体上,当按下鼠标右键,移动鼠标,则窗体随鼠标移动而移动
2个回答
展开全部
Dim onMoving As Boolean
Dim oldx As Single, oldy As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
oldx = X
oldy = Y
onMoving = True
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If onMoving Then
Move Left + X - oldx, Top + Y - oldy
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
onMoving = False
End If
End Sub
展开全部
Dim mx As Integer, my As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mx = X
my = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Form1.Move Me.Left + (X - mx), Me.Top + (Y - my)
End If
End Sub
很简单:使用一个全局变量记录按下鼠标右键时的坐标(mx,my),然后当Button变量值是2(左键是1,右键是2)的时候,利用Move来计算鼠标移动并同时移动窗体。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询