Drag a borderless form

Source: Internet
Author: User

[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 ,);}

 

 

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.