Moving forms without caption bars

G

Guest

I have a form with the FormBorderStyle = None, i.e. no caption bar, no
borders. But I'd still like to have the possibility to move this form by
using the mouse. Could anybody tell me what to implement to accomplish this?

Thanks!

Bevo
 
T

Timofey Kazakov

Hello, "Bevo"
I have a form with the FormBorderStyle = None, i.e. no caption bar, no
borders. But I'd still like to have the possibility to move this form by
using the mouse. Could anybody tell me what to implement to accomplish this?

You can dispatch WM_NCHITTEST message and tell to Windows that user clicks on caption. Simply override WndProc method:

protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0084) //WM_NCHITTEST
{
base.WndProc(ref m);

if (m.Result == (IntPtr)1) //HTCLIENT. User clicks on the window client area
{
m.Result = (IntPtr)2; //HTCAPTION. Now it's caption
}
}
else
{
base.WndProc(ref m);
}
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well, that depend of what mouse action you want to be interpreted as a
"move window" action.

I think that winamp as a similar thing, if you click and drag the window it
does move it.
You can handle these events accordinly.

Then you may use Form.Location to reflect the mouse movement.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top