"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Can I Make a Borderless Form Movable?

How Can I Make a Borderless Form Movable?

Posted on 2025-03-24
Browse:373

How Can I Make a Borderless Form Movable?

Create a removable borderless form

In the graphical user interface, windows with borders are common and users can move them by dragging them. However, some applications may require borderless windows for specific aesthetic effects or functionality. But how do you make these borderless windows moveable?

Solution

An effective technique for creating removable borderless forms is to use Windows API functions:

  1. Define two constants: WM_NCLBUTTONDOWN represents the message sent when the left mouse button is pressed on the window, and HT_CAPTION means that the click occurs in the title bar.

  2. Import the necessary functions: SendMessage Send a message to the window, ReleaseCapture ReleaseCapture

    Release the mouse capture.
  3. In the MouseDown

    event handler of the form:
    • Check whether the left mouse button has been pressed.
    • If yes, release the mouse capture and send a message to the window using WM_NCLBUTTONDOWN and set wParam to HT_CAPTION
    • .

This code actually simulates the mouse click on the title bar, allowing the form to be moved as usual.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3