vb 请教如何使窗体上的标签会随着鼠标的拖拽移动位置
这是原来的代码可以使标签移动PrivatepxAsSingle,pyAsSinglePrivateMDAsBooleanPrivateSubLabel1_MouseDow...
这是原来的代码可以使标签移动
Private px As Single, py As Single
Private MD As Boolean
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
px = X
py = Y
MD = True
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True Then
Label1.Move Label1.Left + (X - px), Label1.Top + (Y - py)
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MD = False
End Sub
我现在想把标签限制在 (X > 2520 And X < 4560 And Y < 3840 And Y > 1320)这样的范围内,就是如果拖动超过了这个范围则无效,只能让标签在这个范围内拖动!
不行呀,一楼的试了没有哦! 展开
Private px As Single, py As Single
Private MD As Boolean
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
px = X
py = Y
MD = True
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True Then
Label1.Move Label1.Left + (X - px), Label1.Top + (Y - py)
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MD = False
End Sub
我现在想把标签限制在 (X > 2520 And X < 4560 And Y < 3840 And Y > 1320)这样的范围内,就是如果拖动超过了这个范围则无效,只能让标签在这个范围内拖动!
不行呀,一楼的试了没有哦! 展开
展开全部
'前提是Label1已经在这个范围里面了,不然得死拽了
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True Then
a = Label1.Left + (X - px)
b = Label1.Top + (Y - py)
If a > 2520 And a < 4560 And b < 3840 And b > 1320 Then
Label1.Move a, b
End If
End If
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True Then
a = Label1.Left + (X - px)
b = Label1.Top + (Y - py)
If a > 2520 And a < 4560 And b < 3840 And b > 1320 Then
Label1.Move a, b
End If
End If
End Sub
展开全部
换成这样
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True and X > 2520 And X < 4560 And Y < 3840 And Y > 1320 Then
Label1.Move Label1.Left + (X - px), Label1.Top + (Y - py)
End If
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MD = True and X > 2520 And X < 4560 And Y < 3840 And Y > 1320 Then
Label1.Move Label1.Left + (X - px), Label1.Top + (Y - py)
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询