Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

winforms

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

like image 283
Basuro Avatar asked Nov 13 '22 03:11

Basuro


1 Answers

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

like image 124
Patrick Geyer Avatar answered Nov 14 '22 22:11

Patrick Geyer