To drag a form in the client area with C # implementation
Source: Internet
Author: User
When you design an application, you may want the user to be able to drag the form through the client area, such as when the form does not have a title bar or create an irregular form, and the form is dragged through the client area.
A good example of what is happening around us is Microsoft Windows Media Player. Media player has a feature that allows you to change the appearance (skin-changing) of the user's hobby, and the title bar is hidden, but you can drag the form through the client area.
All right, let's get down to our journey.
You must first understand the message passing mechanism of windows, and when there is a mouse activity message, the system sends a WM_NCHITTEST message to the form as the basis for judging the occurrence of the message. If you click on the title bar, the form received the message value is Htcaption, similarly, if the message received is Htclient, indicating that the user clicks the customer area, that is, the mouse message occurred in the customer area.
When overloading the form's WndProc method, you can intercept the WM_NCHITTEST message and change the message, when judging the mouse event occurs in the client area, rewrite the change message, send the htcaption to the form, so that the message from the form will be htcaption, Dragging a form in the client area by mouse is like dragging through the title bar.
Note: When you overload WndProc and overwrite mouse events, the entire form's mouse events change.
Example:
1. Create a C # engineering file, the default form is Form1.
2. Click Code on the View panel.
3. Paste the following code into the Form1 class
Private Const int wm_nchittest = 0x84;
Private Const int htclient = 0x1;
Private Const int htcaption = 0x2;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.