16

I have a WinForms application, which is set to full screen mode when I login.

My problem is it's covering the Windows taskbar also. I don't want my application to cover the taskbar.

How can this be done?

p.campbell
  • 95,348
  • 63
  • 249
  • 319
user698065
  • 217
  • 2
  • 4
  • 10

11 Answers11

47

The way I do it is via this code:

this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
this.WindowState = FormWindowState.Maximized;
Arcanox
  • 1,270
  • 10
  • 19
  • 5
    I think this should be the approved answer because the solution offered above does not allow for the normal Windows state change behavior. – mohnston Jan 24 '17 at 01:20
  • 1
    The accepted answer is basically stackoverflow rep hunt in a nutshell; Come up with an imperfect solution a 1st grader can come up with. This is what OP asked for, this! – IOviSpot Apr 08 '21 at 15:11
30

This is probably what you want. It creates a 'maximized' window without hiding the taskbar.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e )
    {
        FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        Left = Top = 0;
        Width = Screen.PrimaryScreen.WorkingArea.Width;
        Height = Screen.PrimaryScreen.WorkingArea.Height;
    }
}
Per
  • 1,064
  • 6
  • 19
5

I had answer it here:

One thing I left out of the description--I'd turned off the maximize button. When I tested turning that property back on, the task bar showed up again. Apparently it assumes if you don't want a maximize button you are creating a kiosk-style application where you don't want your users to see anything but the application screen. Not exactly what I'd expect, but works I guess.

I had this problem and solved it by Jeff's help. First, set the windowstate to Maximized. but Do not disable the MaximizeBox. Then if you want MaximizeBox to be disabled you should do it programmatically:

private void frmMain_Load(object sender, EventArgs e)
{
    this.MaximizeBox = false;
}
Community
  • 1
  • 1
Mostafa Zare
  • 155
  • 1
  • 5
3

Arcanox's answer is great for a single monitor, but if you try it on any screen other than the leftmost, it will just make the form disappear. I used the following code instead.

var workingArea = Screen.FromHandle(Handle).WorkingArea;
MaximizedBounds =  new Rectangle(0, 0, workingArea.Width, workingArea.Height);
WindowState = FormWindowState.Maximized;

The only difference is I'm overriding the top & left values to be 0, 0 since they will be different on other screens.

Brandon B
  • 31
  • 2
  • 1
    i resolve it like this: Size = Screen.FromHandle(Handle).WorkingArea.Size; Location = Screen.FromHandle(Handle).WorkingArea.Location; – Sergio Villalobos Jan 24 '20 at 20:19
2

If you have multiple screens, you have to reset location of MaximizedBounds :

Rectangle rect = Screen.FromHandle(this.Handle).WorkingArea;
rect.Location = new Point(0, 0);
this.MaximizedBounds = rect;
this.WindowState = FormWindowState.Maximized;
1

I'm not good at explaining but this is the code I used to maximize or to full screen the winforms which would not cover up the taskbar. Hope it helps. ^^

private void Form_Load(object sender, EventArgs e)
{
    this.Height = Screen.PrimaryScreen.WorkingArea.Height;
    this.Width = Screen.PrimaryScreen.WorkingArea.Width;
    this.Location = Screen.PrimaryScreen.WorkingArea.Location;
}
Fred Kleuver
  • 7,547
  • 2
  • 24
  • 38
Rein
  • 11
  • 4
1

If Maximizing isn't what you're looking for, then you'll need to calculate the window size yourself by checking for the location and size of the taskbar:

find-out-size-and-position-of-the-taskbar

bradenb
  • 783
  • 4
  • 10
1

If you want to use WindowState = Maximized;, you should first indicate the size limits of the form maximized by the MaximizedBounds property...

Example:

MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
WindowState = FormWindowState.Maximized;

Where are you limiting the size of your form to the work area that is the desktop area of ​​the display

Shuhel Ahmed
  • 953
  • 8
  • 14
0

Try without FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; and comment line like :

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e )
    {
        // FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        Left = Top = 0;
        Width = Screen.PrimaryScreen.WorkingArea.Width;
        Height = Screen.PrimaryScreen.WorkingArea.Height;
    }
}
0
private void frmGateEntry_Load(object sender, EventArgs e)
    {
        // set default start position to manual  
        this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;

        // set position and size to the Form.  
        this.Bounds = Screen.PrimaryScreen.WorkingArea;
    }
0

This was very useful to me:

private void Form1_Load(object sender, EventArgs e)
   {
       this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
       this.WindowState = FormWindowState.Maximized;
   }
Samer_Azar
  • 403
  • 1
  • 9
  • 30