Move a form that doesn't have a titlebar

Here's how to move a form that doesn't have a titlebar:

using System;

using System.Runtime.InteropServices; using System.Windows.Forms;

namespace MoveFormWithoutTitlebar { public partial class Form1 : Form {

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

    [DllImportAttribute("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd,
                     int Msg, int wParam, int lParam);

    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();


    public Form1() {
        InitializeComponent();
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }
}

}


Author: kyrathasoft

The only programmer in Glens Fork, Ky.