469,072 Members | 1,821 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

Moving a captionless form -- Revisited

If I have a form in my project for which I have set the border style to
None, I can use the code below to enable moving the form by clicking
and dragging anywhere on the form:

protected override void WndProc(ref Message m)
{
const int WmNcHitTest = 0x84;
const int HtCaption = 2;

if (m.Msg == WmNcHitTest)
m.Result = new IntPtr(HtCaption);
else
base.WndProc(ref m);
}

It works quite well and the form moves smoothly.

My next question concerns having a panel on the form that completely
covers the form's surface. Is there any way to allow the same
functionality by clicking and dragging on the panel so that the entire
form moves? I would prefer to use a method similar to above rather
than mouse events. Is it possible?

Thanks,

Chris

Apr 11 '06 #1
1 1660
In answer to my own question, I discovered this:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr
wParam, IntPtr lParam);

private void pnlAdmin_MouseDown(object sender, MouseEventArgs
e)
{
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MOVE = 0xF010;
const int HtCaption = 2;

pnlAdmin.Capture = false;

SendMessage(this.Handle, WM_SYSCOMMAND, new IntPtr(SC_MOVE
+ HtCaption),new IntPtr(0));
}

Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Roger Price | last post: by
1 post views Thread by All Rise | last post: by
2 posts views Thread by Diogo Alves - Software Developer | last post: by
14 posts views Thread by bwadley | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.