我也不知道爲何要自定義一個沒差的WinForm,反正就是遇到了MyForm沒法用鼠標拖着走的問題,百度到的解決方案,記錄一下:再把函數
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool 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 tab_title_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************調用移動無窗體控件函數 }
再把tab_title_MouseDown方法給任務欄的MouseDown事件註冊進去就行了:this
public LargeIcoMainForm() { InitializeComponent(); this.tab_title.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tab_title_MouseDown); }
完美。spa