Click here to Skip to main content
14,575,277 members

Dragging a Borderless Form

Rate this:
4.94 (9 votes)
Please Sign up or sign in to vote.
4.94 (9 votes)
12 Jun 2010CPOL
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)

Share

About the Author

Kristian Sixhøj
Student
Denmark Denmark

New biography coming sometime.
Green Alien | [Alien]


Comments and Discussions

 
QuestionContainers? Pin
HiMik200331-May-10 23:08
MemberHiMik200331-May-10 23:08 
AnswerRe: Containers? Pin
Kristian Sixhøj31-May-10 23:12
MemberKristian Sixhøj31-May-10 23:12 
GeneralRe: Containers? Pin
HiMik200331-May-10 23:32
MemberHiMik200331-May-10 23:32 
GeneralRe: Containers? Pin
Kristian Sixhøj31-May-10 23:37
MemberKristian Sixhøj31-May-10 23:37 
GeneralRe: Containers? Pin
HiMik200331-May-10 23:44
MemberHiMik200331-May-10 23:44 
GeneralRe: Containers? Pin
Kristian Sixhøj31-May-10 23:59
MemberKristian Sixhøj31-May-10 23:59 
GeneralRe: Containers? Pin
HiMik20031-Jun-10 0:39
MemberHiMik20031-Jun-10 0:39 
AnswerRe: Containers? Pin
Dima Popov13-Jul-10 3:27
MemberDima Popov13-Jul-10 3:27 
GeneralRe: Containers? Pin
HiMik200315-Jul-10 3:40
MemberHiMik200315-Jul-10 3:40 

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

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

Tip/Trick
Posted 31 May 2010

Tagged as

Stats

26.9K views
7 bookmarked