[Instance description]
Generally, the form contains the title bar, menu bar, toolbar, and status bar. When you drag a form, press and hold the left mouse button in the title bar to drag the form.
If a floating form contains a border, the interface is unfriendly to the user. Therefore, the floating form does not have a border, but for such a form without a border, how do I drag and drop Data?
This example will lead the reader to create a program to drag a borderless form.
[Key Technologies]
In this example, two Windows API functions are used: ReleaseCapture and SendMessage.
(1) ReleaseCapture Function
This function is used to release the cursor captured by a window in the current thread. The syntax format is as follows:
[DllImport( ReleaseCapture();
Note: When using System API functions in a program, you must first add the System. Runtime. InteropServices namespace in The namespace area.
(2) SendMessage Function
This function is used to send Windows messages to a specified form. The syntax format is as follows:
[DllImport( SendMessage(IntPtr hwdn, wMsg, mParam, lParam);
Note: For detailed parameters and comments, see mark them in the file code.
Design Process]
(1) Open Visual Studio and create a WinForm application named DragNoFrameForm.
(2) Change the Name attribute of the default form Form1 to Frm_Main, and set the FormBorderStyle attribute of the form to None.
(3) The main code of the program is as follows:
The API functions used in this program [DllImport (ReleaseCapture (); [DllImport (SendMessage (IntPtr hwdn, wMsg, mParam, the variable to be declared in this program WM_SYSCOMMAND =; SC _MOVE =; HTCAPTION =; ExitContext_Click (Application. exit (); Frm_Main_MouseDown (ReleaseCapture (); SendMessage (. handle, WM_SYSCOMMAND, SC _MOVE + HTCAPTION ,);}