Showing posts with label Move Form. Show all posts
Showing posts with label Move Form. Show all posts

Friday, February 8, 2008

Moving a Form whose borderstyle is set to None

If a form's 'FormBorderStyle' property is set to none.Then the form wont be movable.To make the form movable a small script can be added to code.Its included below.This will make the form movable as it considers all part of the form as caption.

protected override void WndProc(ref Message m)
{
// Let the base class have first crack
base.WndProc(ref m);
int WM_NCHITTEST = 0x84; // winuser.h
// If the user clicked on the client area,
// ask the OS to treat it as a click on the caption
if (m.Msg != WM_NCHITTEST) return;
int HTCLIENT = 1;
int HTCAPTION = 2;
if (m.Result.ToInt32() == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
}