full screen mode, but don't cover the taskbar
Asked Answered
D

13

23

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?

Doghouse answered 20/6, 2011 at 17:31 Comment(3)
That's kind of the definition of full screen. Perhaps you want to be setting it to "Maximize" instead?Kao
@Evil: you should have had answered the question with your question.Netta
@The E : I set it to this.windowstate = maximised...Doghouse
B
31

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;
    }
}
Brecher answered 20/6, 2011 at 17:39 Comment(0)
D
64

The way I do it is via this code:

this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
this.WindowState = FormWindowState.Maximized;
Dynamometry answered 24/3, 2015 at 9:11 Comment(3)
I think this should be the approved answer because the solution offered above does not allow for the normal Windows state change behavior.Stoop
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!Epicardium
This works for my primary monitor. Once I move my app to my secondary monitor, same resolution, the application disappears.Neuroglia
B
31

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;
    }
}
Brecher answered 20/6, 2011 at 17:39 Comment(0)
D
6

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;
}
Doily answered 18/3, 2013 at 13:38 Comment(0)
L
6

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.

Loiret answered 13/11, 2019 at 15:45 Comment(1)
i resolve it like this: Size = Screen.FromHandle(Handle).WorkingArea.Size; Location = Screen.FromHandle(Handle).WorkingArea.Location;Fruitarian
T
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;
Trilateration answered 17/2, 2017 at 17:14 Comment(0)
A
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

Amadeus answered 20/6, 2011 at 17:35 Comment(0)
S
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

Sverre answered 20/6, 2011 at 17:47 Comment(0)
X
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;
}
Xavier answered 13/6, 2017 at 10:18 Comment(1)
Some explanations about this code-only answer would probably be beneficial!Imitation
T
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;
    }
}
Taryn answered 17/12, 2013 at 11:47 Comment(0)
I
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;
    }
Ilowell answered 20/2, 2016 at 15:2 Comment(0)
A
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;
   }
Admass answered 2/3, 2022 at 21:8 Comment(0)
N
0

I know it's a bit too late, but it will help others too in the future.

the answered code above is working but still in my case if the taskbar is auto-hiding and showing it wont show the taskbar once it hides from the screen. I solved this problem by adding -1` to the working area height.

var workingArea = Screen.FromHandle(Handle).WorkingArea;
MaximizedBounds = new Rectangle(0, 0, workingArea.Width, workingArea.Height - 1);
Nerin answered 9/9, 2022 at 3:25 Comment(0)
A
-1
private void btnMaximixar_Click(object sender, EventArgs e)
    {
        MaximumSize = new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
        WindowState = FormWindowState.Maximized;
    }
Agonize answered 18/7, 2023 at 5:23 Comment(2)
This answer is not as good as the answer from Arcanox (which is 8 years old), because you assume you're on the main screen (by picking AllScreens[0]). If you're on multi desktop environment you have to pick the correct screen, which is handled by the answer from Arcanox by picking Screen.FromHandle(this.Handle).Clemmieclemmons
Answer needs supporting information Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Rothstein

© 2022 - 2024 — McMap. All rights reserved.