新建一個類 using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace BRO { class DragControl { //c#拖动无标题窗体 [DllImport("user32.dll")] private static extern bool ReleaseCapture(); [DllImport("user32.dll")] private static extern bool SendMessage(System.IntPtr hwnd, int wMsg, int wParam, int lParam); private const int WM_SYSCOMMAND = 0x0112; private const int SC_MOVE = 0xF010; private const int HTCAPTION = 0x0002; internal System.Windows.Forms.Control m_DragUI = null; public static void SetDrag(System.Windows.Forms.Control control) { // Control ctlBottomChild=control.find DragControl dragControl = new DragControl(); dragControl.m_DragUI = control; dragControl.m_DragUI.MouseDown += new System.Windows.Forms.MouseEventHandler(m_DragUI_MouseDown); } private static void m_DragUI_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { ReleaseCapture(); Control ctlDragControl = sender as Control; if (ctlDragControl is System.Windows.Forms.Form) SendMessage(ctlDragControl.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); else SendMessage(ctlDragControl.FindForm().Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } //private static System.Windows.Forms.Control GetControl(System.Windows.Forms.Control control) //{ // if (control.Controls.Count > 0) // { // return control. // } //} } } 然後在自定義窗口的構造函數中 如下使用即可 public RegisterForm() { InitializeComponent(); DragControl.SetDrag(this); }