'在窗体上覆盖panel控件,如果直接是窗体,选择Form的MouseDown,MouseMove,MouseUp时间即可
Private Sub Panel1_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
Me.bFormDragging = True
Me.oPointClicked = New Point(e.X,e.Y)
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If Me.bFormDragging Then
Dim oMoveToPoint As Point
oMoveToPoint = Me.PointToScreen(New Point(e.X,e.Y))
oMoveToPoint.Offset(Me.oPointClicked.X * -1,(Me.oPointClicked.Y + SystemInformation.CaptionHeight + SystemInformation.BorderSize.Height) * -1)
Me.Location = oMoveToPoint
End If
End Sub
Private Sub Panel1_MouseUp(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
Me.bFormDragging = False
End Sub
API移动窗体
Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As IntPtr,_
ByVal wMsg As Integer,_
ByVal wParam As Integer,_
ByVal lParam As Integer) _
As Boolean
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Boolean
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub Form1_MouseDown(ByVal sender As Object,_ ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles MyBase.MouseDown ReleaseCapture() SendMessage(Me.Handle,WM_SYSCOMMAND,SC_MOVE + HTCAPTION,0) End Sub