This is a post to everyone who has ever asked himself "how do I maximize a window in my multi-screen setup without blocking the task bar".
The problem seems to be that a window that has MaximizeBox and MinimizeBox set to false and that gets maximized programmatically in a multi-screen environment covers the entire screen, not only the Screen.WorkingArea.
To maximize a window to the working area only, one needs to utilize the MaximizeBox and MinimizeBox properties like so:
// This code should be placed in the Form's ResizeEnd handler
MaximizeBox = MinimizeBox = true; // Enable both boxes
WindowState = FormWindowState.Maximized; // Set to maximized
MaximizeBox = MinimizeBox = false; // Disable both boxes again
Thus, the window will be nicely maximized on the screen and respect the screen's working area (not block the task bar).
Or you could set this.MaximumSize to new Size (screen.primaryscreen.bounds.width + screen.secondaryscreen.bounds.width, screen.primaryscreen.bounds.height).
P.S. I wrote this from my phone so I cannot check syntax etc... and also why did you post this as a 'question'?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With