Public Declare Function ReleaseCapture Lib "user32.dll" Alias "ReleaseCapture" () As Integer
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = MouseButtons.Left Then
'为当前的应用程序释放鼠标捕获
ReleaseCapture()
'发送消息,让系统误以为你在标题拦上按下鼠标
SendMessage(Me.Handle.ToInt32, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End If
End Sub
'----------------------------------------------------------------------------
C#下
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int ReleaseCapture();
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage