How to override form's Maximize button operation?

From: Dave Leach (babel_at_newsgroup.nospam)
Date: 03/03/05


Date: Thu, 3 Mar 2005 11:25:09 -0800

I am developing a Windows Forms application in VS.NET 2003 and C#. The
application is using the MDI style. I have one or more child forms visible
in the client area of the main form.

I want to keep the MaximizeBox property set to True so that the user can
click the maximize button on the title bar. However, I want to catch this
event and perform my own version of a maximize operation. I have tried
catching the SW_MAXIMIZE message in the child form's WndProc and call my own
max function, but it still does the normal maximize operation. See sample
code below.

How can I override this message or event?

Thanks,
Dave

######## Code #######

protected override void WndProc( ref Message m )
{
  if ( m.Msg == User32DllImports.SW_MAXIMIZE )
  {
    Debug.WriteLine( "SW_MAXIMIZE message." );
    this.Zoom( mdiParent.UsableClientAreaSize() );
    return;
  }
}

###################