Moon Moon - 1 year ago 125
C# Question

How to move a Windows Form when its FormBorderStyle property is set to None?

Using C#.

I am trying to move a

without its title bar.

I found an article about it on:

It works as long as I do not set

Is there a way to make it work with this property set as

Answer Source

I know this question is over a year old, but I was searching trying to remember how I've done it in the past. So for anyone else's reference, the quickest and less complex way then the above link is to override the WndProc function.

Constants in Windows API
0x84 = WM_NCHITTEST - Mouse Capture Test
0x1 = HTCLIENT - Application Client Area
0x2 = HTCAPTION - Application Title Bar

This function intercepts all the commands sent to the application. 
It checks to see of the message is a mouse click in the application. 
It passes the action to the base action by default. It reassigns 
the action to the title bar if it occured in the client area
to allow the drag and move behavior.

protected override void WndProc(ref Message m)
        case 0x84:
            base.WndProc(ref m);
            if ((int)m.Result == 0x1)
                m.Result = (IntPtr)0x2;

    base.WndProc(ref m);

This will allow any form to be moved by clicking and dragging within the client area.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download