- The title bar area is encapsulated within the Panel container (recommended), then the panel's MouseDown event handler is written.
[C-sharp]View Plaincopyprint?
- [DllImport ("user32.dll", CharSet = CharSet.Unicode)]
- Public static extern IntPtr SendMessage (IntPtr hwnd, int wmsg, IntPtr wParam, IntPtr lParam);
- [DllImport ("user32.dll", CharSet = CharSet.Unicode)]
- Public static extern bool ReleaseCapture ();
- Private void Panelcaption_mousedown (object sender, MouseEventArgs e)
- {
- const int wm_nclbuttondown = 0x00A1;
- const int htcaption = 2;
- if (E.button = = MouseButtons.Left) //Press the left mouse button
- {
- ReleaseCapture ();
- SendMessage (This. Handle, Wm_nclbuttondown, (INTPTR) htcaption, IntPtr.Zero); //Drag the form
- }
- }
[DllImport ("user32.dll", CharSet = charset.unicode)]public static extern IntPtr SendMessage (IntPtr hwnd, int wmsg, INTPTR WParam, IntPtr LParam); [DllImport ("user32.dll", CharSet = charset.unicode)]public static extern bool ReleaseCapture ();p rivate void Panelcaption_mousedown (object sender, MouseEventArgs e) {const int wm_nclbuttondown = 0x00A1; Const int htcaption = 2; if (E.button = = mousebuttons.left)//press the left mouse button {releasecapture (); SendMessage (this. Handle, Wm_nclbuttondown, (INTPTR) htcaption, IntPtr.Zero); Drag the form}}
- The title bar area is placed directly on the form, overriding the form's onmousedown function.
[C-sharp]View Plaincopyprint?
- [DllImport ("user32.dll", CharSet = CharSet.Unicode)]
- Public static extern IntPtr SendMessage (IntPtr hwnd, int wmsg, IntPtr wParam, IntPtr lParam);
- [DllImport ("user32.dll", CharSet = CharSet.Unicode)]
- Public static extern bool ReleaseCapture ();
- Protected override void OnMouseDown (MouseEventArgs e)
- {
- const int wm_nclbuttondown = 0x00A1;
- const int htcaption = 2;
- base. OnMouseDown (e);
- if (E.button = = MouseButtons.Left) //Press the left mouse button
- {
- ReleaseCapture (); //Release capture
- SendMessage (This. Handle, Wm_nclbuttondown, (INTPTR) htcaption, IntPtr.Zero); //Drag the form
- }
- }
|