1. Rewrite WndProc
protected Override voidWndProc (refMessage m) { Const intWm_nchittest =0x84; Const intHtclient =0x01; Const intHtcaption =0x02; if(M.msg = =wm_nchittest) { This. Defwndproc (refm); if(M.result.toint32 () = =htclient) M.result=NewIntPtr (htcaption); Else Base. WndProc (refm); } Else { Base. WndProc (refm); }}View Code
2. Create a message
Private Const intWm_nclbuttondown =0x00A1;Private Const intWm_nchittest =0x84;Private Const intHt_caption =0x2;Private Const intHt_client =0x1;Private voidPicturebox1_mousedown (Objectsender, MouseEventArgs e) { //This . Capture = false;Picturebox1.capture =false; Message msg=message.create (Handle, Wm_nclbuttondown, (INTPTR) ht_caption, IntPtr.Zero); WndProc (refmsg); } View Code
3. Calling API Code
usingSystem.Runtime.InteropServices; [DllImport ("user32.dll")] Public Static extern BOOLreleasecapture (); [DllImport ("user32.dll")] Public Static extern BOOLSendMessage (INTPTR hwnd,intWmsg,intWParam,intLParam); Public Const intWm_syscommand =0x0112; Public Const intSc_move =0xf010; Public Const intHtcaption =0x0002; //Add the following code to the form's _mousedown:such as:Private voidForm1_mousedown (Objectsender, System.Windows.Forms.MouseEventArgs e) {releasecapture (); SendMessage ( This. Handle, Wm_syscommand, Sc_move + htcaption,0);}View Code
C # Three ways to move a borderless form