Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Dragging a Borderless Form

0.00/5 (No votes)
12 Jun 2010 1  
A code snippet which makes a borderless form draggable.
I was looking through some old C# projects on my external hard drive, when I stumbled upon the following code snippet, which makes a borderless form draggable.

C#
protected override void WndProc(ref Message m)
{
    if (m.Msg == 163 && this.ClientRectangle.Contains(this.PointToClient(new Point(m.LParam.ToInt32()))) && m.WParam.ToInt32() == 2)
        m.WParam = (IntPtr)1;
    base.WndProc(ref m);
    if (m.Msg == 132 && m.Result.ToInt32() == 1)
        m.Result = (IntPtr)2;
}


This makes the form draggable by clicking and dragging anywhere on the form itself (that is, not on controls unless they are disabled).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here