Click here to Skip to main content
13,250,182 members (71,026 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

20.6K views
7 bookmarked
Posted 31 May 2010

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)

Share

About the Author

Kristian Sixhoej
Student
Denmark Denmark

New biography coming sometime.
Green Alien | [Alien]


You may also be interested in...

Comments and Discussions

 
QuestionContainers? Pin
HiMik20031-Jun-10 0:08
memberHiMik20031-Jun-10 0:08 
AnswerRe: Containers? Pin
Kristian Sixhoej1-Jun-10 0:12
memberKristian Sixhoej1-Jun-10 0:12 
GeneralRe: Containers? Pin
HiMik20031-Jun-10 0:32
memberHiMik20031-Jun-10 0:32 
GeneralRe: Containers? Pin
Kristian Sixhoej1-Jun-10 0:37
memberKristian Sixhoej1-Jun-10 0:37 
GeneralRe: Containers? Pin
HiMik20031-Jun-10 0:44
memberHiMik20031-Jun-10 0:44 
GeneralRe: Containers? Pin
Kristian Sixhoej1-Jun-10 0:59
memberKristian Sixhoej1-Jun-10 0:59 
GeneralRe: Containers? Pin
HiMik20031-Jun-10 1:39
memberHiMik20031-Jun-10 1:39 
Thank you. I hove that threre is a solution like below, but it does not work Frown | :(
if (m.Msg == 163 // 0xA3 WM_NCLBUTTONDBLCLK
    && m.WParam.ToInt32() == 2
    && (this.ClientRectangle.Contains(this.PointToClient(new Point(m.LParam.ToInt32())))
    || panel1.ClientRectangle.Contains(panel1.PointToClient(new Point(m.LParam.ToInt32()))))
    )
    m.WParam = (IntPtr)1;

AnswerRe: Containers? Pin
KPEBEDKO13-Jul-10 4:27
memberKPEBEDKO13-Jul-10 4:27 
GeneralRe: Containers? Pin
HiMik200315-Jul-10 4:40
memberHiMik200315-Jul-10 4: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 12 Jun 2010
Article Copyright 2010 by Kristian Sixhoej
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid