label控件可以用鼠标拖动,但没有边界,附代码,请老师们给点意见如何定义边界~~~~~
Public Class tftest
Dim ss As Boolean
Dim mov As Point
Private Sub Label1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
ss = True
mov = New Point(e.X, e.Y)
End Sub
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
ss = False
End Sub
Private Sub Label1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
Dim a, b As Integer
a = mov.X - e.X
b = mov.Y - e.Y
TextBox1.Text = a
TextBox2.Text = b
If ss = True And Me.Label1.Left >= 10 And Me.Label1.Left < Me.Width - Me.Label1.Width Then
Me.Label1.Left = Me.Label1.Left - a
End If
If ss = True And Me.Label1.Top > 0 And Me.Label1.Top < Me.Height - Me.Label1.Height Then
Me.Label1.Top = Me.Label1.Top - b
End If
End Sub
Private Sub Label1_Move(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Move
If Me.Label1.Left < 10 Then
Me.Label1.Left = 10
End If
End Sub
End Class