Basuro
Basuro

Reputation: 1104

Maximizing a window in a multi-screen environment without hiding/blocking the task bar

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

Upvotes: 5

Views: 752

Answers (2)

ChirpingPanda
ChirpingPanda

Reputation: 50

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

Upvotes: 0

Patrick Geyer
Patrick Geyer

Reputation: 1535

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

Upvotes: 1

Related Questions