Here's one possibility...
Add a property to the Owned form to track its last FormWindowState
(could just be private
if you don't care to expose it):
private FormWindowState _lastState;
public FormWindowState LastWindowState { get { return _lastState; } }
Add an override for WndProc
to the Owned form:
protected override void WndProc(ref Message message)
{
const Int32 WM_SYSCOMMAND = 0x0112;
const Int32 SC_MAXIMIZE = 0xF030;
const Int32 SC_MINIMIZE = 0xF020;
const Int32 SC_RESTORE = 0xF120;
switch (message.Msg)
{
case WM_SYSCOMMAND:
{
Int32 command = message.WParam.ToInt32() & 0xfff0;
switch (command)
{
case SC_MAXIMIZE:
_lastState = FormWindowState.Maximized;
break;
case SC_MINIMIZE:
_lastState = FormWindowState.Minimized;
break;
case SC_RESTORE:
_lastState = FormWindowState.Normal;
break;
}
}
break;
}
base.WndProc(ref message);
}
Finally, add a handler for the Owned form's VisibleChanged
event:
private void Form2_VisibleChanged(object sender, EventArgs e)
{
WindowState = _lastState;
}