5
votes

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).

2
This is a good question...Philip Gullick
I know it's not really a question ;) but the question behind this.. "How do I do that" pops up so often that I thought it might be useful to post itBasuro
No, it was simply sarcasm.Philip Gullick
And to think that I previously used a WinAPI hack to calculate the area myself... Thanks for this!Honza Brestan
@WiiMaxx will remember your suggestion for next time.Basuro

2 Answers

1
votes

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'?

0
votes

I found that using the ResizeEnd event still covered the task bar. So used the Load event instead; no obscured task bar.