If you don't like using the form's WindowState
property and don't want to have to keep around a flag indicating the form's previous state, you can achieve the same result at a slightly lower level.
You'll need to override your form's window procedure (WndProc
) and listen for a WM_SYSCOMMAND
message indicating SC_RESTORE
. For example:
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_RESTORE = 0xF120;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_RESTORE)
{
// Do whatever processing you need here, or raise an event
// ...
MessageBox.Show("Window was restored");
}
base.WndProc(ref m);
}