user698065
user698065

Reputation: 317

full screen mode, but don't cover the taskbar

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?

Upvotes: 24

Views: 53594

Answers (13)

Roberto Cardonne
Roberto Cardonne

Reputation: 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;
    }

Upvotes: -1

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

Upvotes: 0

Samer_Azar
Samer_Azar

Reputation: 433

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;
   }

Upvotes: 0

Brandon B
Brandon B

Reputation: 61

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.

Upvotes: 6

bradenb
bradenb

Reputation: 793

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

Upvotes: 1

Shuhel Ahmed
Shuhel Ahmed

Reputation: 963

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

Upvotes: 1

Rein
Rein

Reputation: 21

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;
}

Upvotes: 1

user7582072
user7582072

Reputation: 21

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;

Upvotes: 2

Lisa Ganmara
Lisa Ganmara

Reputation: 1

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;
    }

Upvotes: 0

Arcanox
Arcanox

Reputation: 1547

The way I do it is via this code:

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

Upvotes: 65

user3040632
user3040632

Reputation: 13

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;
    }
}

Upvotes: 0

Mostafa Zare
Mostafa Zare

Reputation: 185

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;
}

Upvotes: 8

Per
Per

Reputation: 1084

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;
    }
}

Upvotes: 31

Related Questions