user user - 7 months ago 54
C# Question

Make a borderless form movable?

Is there a way to make a form that has no border (FormBorderStyle is set to "none") movable when the mouse is clicked down on the form just as if there was a border? Thanks.


This article on CodeProject details a technique. Is basically boils down to:

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;

public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public static extern bool ReleaseCapture();

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    if (e.Button == MouseButtons.Left)
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

This essentially does exactly the same as grabbing the title bar of a window, from the window manager's point of view.