B
Benny Raymond
I'm currently trying to implement a Form that uses the BorderStyle
"None" property but still allows the user to resize, move the window
around, etc.
This is all working correctly - now I run into a problem where I really
want the window to have a border, but I want it to have just a small
line as a border. Idealy I'd want to use a GroupBox or something to
make everything easy - the problem i'm having is that once the groupbox
is on the form the NCHITTEST doesn't fire anymore because the mouse is
hitting the GroupBox instead of the Form. Also the HTCLOSE doesn't
work, I'm assuming it's because this Form is borderless?
Obviously this is a lot more complicated but I was just wondering what
you guys thought of the whole situation and what you'd do in this case.
Here's my current wndproc code:
protected override void WndProc(ref Message m)
{
int x = MsgParams.LoWord(m.LParam.ToInt32());
int y = MsgParams.HiWord(m.LParam.ToInt32());
Point p = new Point(x, y);
p = this.PointToClient(p);
switch (m.Msg)
{
case (int)MSG.WM_NCHITTEST:
DefWndProc(ref m);
if (p.X < 15 && p.Y > (this.Height - 15))
{
// Allow resizing on bottom left corner
// eventually have an enum handle which corner
// we're currently allowed to resize and check it
// in another switch case statement.
m.Result = new IntPtr((int)HIT_TEST.HTBOTTOMLEFT);
}
else if (p.Y < 30)
{
// Allow the form to be moved around the screen
// Eventually do not hard code the "30" value.
m.Result = new IntPtr((int)HIT_TEST.HTCAPTION);
}
else if (p.X > this.Width - 15 && p.Y < 15)
{
// Allow the form to be closed in the top right
corner
m.Result = new IntPtr((int)HIT_TEST.HTCLOSE);
}
break;
default:
base.WndProc(ref m);
break;
}
}
"None" property but still allows the user to resize, move the window
around, etc.
This is all working correctly - now I run into a problem where I really
want the window to have a border, but I want it to have just a small
line as a border. Idealy I'd want to use a GroupBox or something to
make everything easy - the problem i'm having is that once the groupbox
is on the form the NCHITTEST doesn't fire anymore because the mouse is
hitting the GroupBox instead of the Form. Also the HTCLOSE doesn't
work, I'm assuming it's because this Form is borderless?
Obviously this is a lot more complicated but I was just wondering what
you guys thought of the whole situation and what you'd do in this case.
Here's my current wndproc code:
protected override void WndProc(ref Message m)
{
int x = MsgParams.LoWord(m.LParam.ToInt32());
int y = MsgParams.HiWord(m.LParam.ToInt32());
Point p = new Point(x, y);
p = this.PointToClient(p);
switch (m.Msg)
{
case (int)MSG.WM_NCHITTEST:
DefWndProc(ref m);
if (p.X < 15 && p.Y > (this.Height - 15))
{
// Allow resizing on bottom left corner
// eventually have an enum handle which corner
// we're currently allowed to resize and check it
// in another switch case statement.
m.Result = new IntPtr((int)HIT_TEST.HTBOTTOMLEFT);
}
else if (p.Y < 30)
{
// Allow the form to be moved around the screen
// Eventually do not hard code the "30" value.
m.Result = new IntPtr((int)HIT_TEST.HTCAPTION);
}
else if (p.X > this.Width - 15 && p.Y < 15)
{
// Allow the form to be closed in the top right
corner
m.Result = new IntPtr((int)HIT_TEST.HTCLOSE);
}
break;
default:
base.WndProc(ref m);
break;
}
}