Home >Backend Development >C++ >Can Borderless Forms Be Made Movable by Clicking on Them?

Can Borderless Forms Be Made Movable by Clicking on Them?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-24 15:47:12371browse

Can Borderless Forms Be Made Movable by Clicking on Them?

Create a movable borderless form

Is it possible to create a borderless form but still be able to move it by clicking on the form itself, just like a bordered form?

Answer:

Yes. CodeProject provides a detailed technique:

Its core solutions include:

<code class="language-c#">public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool ReleaseCapture();

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{     
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}</code>

This method simulates the behavior of grabbing the window title bar by sending a message to the window manager. It simulates a left-click in the title bar area, triggering the same movement mechanism as a bordered form.

The above is the detailed content of Can Borderless Forms Be Made Movable by Clicking on Them?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn