Click here to Skip to main content
Click here to Skip to main content

Dragging a Borderless Form

, 12 Jun 2010
Rate this:
Please Sign up or sign in to vote.
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.
 
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kristian Sixhoej
Student
Denmark Denmark

New biography coming sometime.
Green Alien | [Alien]


Comments and Discussions

 
QuestionContainers? PinmemberHiMik200331-May-10 23:08 
AnswerRe: Containers? PinmemberKristian Sixhoej31-May-10 23:12 
GeneralRe: Containers? PinmemberHiMik200331-May-10 23:32 
GeneralRe: Containers? PinmemberKristian Sixhoej31-May-10 23:37 
GeneralRe: Containers? PinmemberHiMik200331-May-10 23:44 
GeneralRe: Containers? PinmemberKristian Sixhoej31-May-10 23:59 
GeneralRe: Containers? PinmemberHiMik20031-Jun-10 0:39 
AnswerRe: Containers? PinmemberKPEBEDKO13-Jul-10 3:27 
GeneralRe: Containers? PinmemberHiMik200315-Jul-10 3:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 12 Jun 2010
Article Copyright 2010 by Kristian Sixhoej
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid