I am using a borderless form and implemented the form with HTCAPTION so that it can be dragged around. Another benefit of HTCAPTION is that when doubled cliked, it can minimize and maximize. The only problem is that I want to catch an event so that when the window is maximized, I can change the icon of a button from maximize button to normal mode button.
Any great ideas on how to implement this?
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch(m.Msg)
{
case Global.WM_NCHITTEST:
Point mouseCursor = PointToClient(Cursor.Position);
if (mouseCursor.X < borderSize && mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOPLEFT;
else if (mouseCursor.X < borderSize && mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOMLEFT;
else if (mouseCursor.X < borderSize)
m.Result = (IntPtr)Global.HTLEFT;
else if (mouseCursor.X > Width - borderSize && mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOPRIGHT;
else if (mouseCursor.X > Width - borderSize && mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOMRIGHT;
else if (mouseCursor.X > Width - borderSize)
m.Result = (IntPtr)Global.HTRIGHT;
else if (mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOP;
else if (mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOM;
else
m.Result = (IntPtr)Global.HTCAPTION;
break;
}
}
This is the code I want to add in the catched event
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
pb_max.Image = GomeeSoft.Properties.Resources.buttonmax;
}
else
{
Screen screen = Screen.FromRectangle(new Rectangle(Left, Top, Width, Height));
this.MaximumSize = screen.WorkingArea.Size;
WindowState = FormWindowState.Maximized;
pb_max.Image = GomeeSoft.Properties.Resources.buttonreturn;
}
Double-clicking generates WM_SYSCOMMAND messages. Which you can detect with WndProc as well: