vb中 鼠标拖动label移动且不会移出form的边界。求代码,谢谢!
展开全部
Dim oX!, oY!
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oX = X
oY = Y
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X1!, Y1!
If Button <> 1 Then Exit Sub
X1 = Label1.Left + X - oX
Y1 = Label1.Top + Y - oY
If X1 <= 0 Then
X1 = 0
ElseIf X1 > Form1.ScaleWidth - Label1.Width Then
X1 = Form1.ScaleWidth - Label1.Width
End If
If Y1 <= 0 Then
Y1 = 0
ElseIf Y1 > Form1.ScaleHeight - Label1.Height Then
Y1 = Form1.ScaleHeight - Label1.Height
End If
Label1.Left = X1
Label1.Top = Y1
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oX = X
oY = Y
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X1!, Y1!
If Button <> 1 Then Exit Sub
X1 = Label1.Left + X - oX
Y1 = Label1.Top + Y - oY
If X1 <= 0 Then
X1 = 0
ElseIf X1 > Form1.ScaleWidth - Label1.Width Then
X1 = Form1.ScaleWidth - Label1.Width
End If
If Y1 <= 0 Then
Y1 = 0
ElseIf Y1 > Form1.ScaleHeight - Label1.Height Then
Y1 = Form1.ScaleHeight - Label1.Height
End If
Label1.Left = X1
Label1.Top = Y1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询