-2

My C# form (Visual Studio 2008) has an advanced mode with more bells and whistles (larger form size) and also a normal mode (smaller form size).

If a user clicks on the maximize button, I'd like the form to toggle to either advanced mode or normal mode, instead of maximizing the form itself.

Is this possible?

bobbay
  • 483
  • 4
  • 9
  • Overriding `OnSizeChanged `event, may be? – T.S. Oct 03 '15 at 00:08
  • I personally have never seen a really good and elegant solution to this problem of two very different GUI that need to be switched, especially in WinForms. So I would go with something like two panels with the different layouts in it and make them so that the bigger one stretches accordingly(should be done automatically) or something like that. But don't ask me in detail how this would look like. As hooks for switching take a look at the layout events: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.layout(v=vs.110).aspx – SkryptX Oct 03 '15 at 00:23
  • Instead of changing the behavior of the maximize button, you may want to consider adding radio button menu items to the Window's System Menu (e.g. Simple View, Advanced View). – Loathing Oct 03 '15 at 03:36
  • You can intercept the [WM_GETMINMAXINFO](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632626(v=vs.85).aspx) message and change the size/position of the window in it's "maximized state". I've got [an example of here](http://stackoverflow.com/a/16932384/2330053) of how to trap and work with that message. – Idle_Mind Oct 03 '15 at 03:42

1 Answers1

1

I do not believe that there is an WinForms event that will be triggered by the maximize button.

Last time I checked (years ago), what you can do is go down to the WinAPI level.

protected override void WndProc( ref Message m )
    {
        base.WndProc(ref m); // Call overwritten method first
        if( m.Msg == 0x0112 ) // WM_SYSCOMMAND
        {
            if (m.WParam == new IntPtr( 0xF030 ) ) //Window is being maximized
            {
                  // things
            }
        }
    }
Typer525
  • 86
  • 1
  • 8