Maximized screen ignores taskbar
Asked Answered
V

8

8

I have a form I set to Maximized, but for some reason it's ignoring the taskbar and maximizing to the entire screen. Is that typical? Is there a workaround?

I'm running Windows XP with a dual monitor setup (taskbar in the first/primary window).

Vitamin answered 10/6, 2009 at 12:32 Comment(2)
Is ShowInTaskbar property set to False?Heddi
Assign the MaximizedBounds property.Yakut
V
7

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.

Vitamin answered 10/6, 2009 at 12:44 Comment(0)
S
15

If you are using FormBorderStyle.None then it is very simple to make sure it doesn't cover the taskbar when maximized:

this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size;

It will probably work for other border styles and is probably the cleanest way to ensure your form does not cover the taskbar.

Sadomasochism answered 5/11, 2009 at 18:45 Comment(2)
You should probably use Screen.FromControl(this) instead of Screen.PrimaryScreen. If the user has multiple screens, your control won't necessarily be on the primary screen.Roadability
Doesn't work across screens. If you set MaximumSize in form OnMove event you'll end up with a form that is constrained to the screen's width in non-maximized mode (this isn't the default behavior).Porterporterage
V
7

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.

Vitamin answered 10/6, 2009 at 12:44 Comment(0)
M
3

Set the form border to None before making it maximized.

This code will work in a single monitor:

private void Form1_Load(object sender, EventArgs e)
{
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

I haven't tested the dual monitor scenario since i don't have this at this moment. :P

EDIT: I didn't get it "Maximized Screen Ignores Taskbar". What does Ignores mean?

Do you want your form to cover the taskbar and fill the entire screen?

Macule answered 10/6, 2009 at 12:37 Comment(2)
He means that his form covers the whole screen, even hiding the taskbar which he doesn't want.Shoal
To add to that, he should check the FormBorderStyle property of his form and make sure it's NOT set to FormBorderStyle.None.Shoal
C
3

If you don't want to re-enable the maximize button, you could manually set the size of the window :

private void Maximize()
{
    Screen screen = Screen.FromPoint(this.Location);
    this.Size = screen.WorkingArea.Size;
    this.Location = Point.Empty;
}

(WorkingArea is the area of the screen that can be used by applications, excluding the TaskBar and other toolbars)

Canthus answered 10/6, 2009 at 15:18 Comment(3)
Doesn't work -- sys menu maximize doesn't call your Maximize() methodPorterporterage
@ZachSaw, of course it doesn't, why would it? It's a method you have to call yourself.Canthus
That doesn't show up as maximized state at all when you have sysmenu popup!Porterporterage
A
3

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;
}
Ales answered 18/3, 2013 at 13:35 Comment(0)
B
2

Taskbar can be docked at left, top, bottom, right side. If you want maximized window without overlayed taskbar, use this code:


...cut...
  public partial class Form2 : Form
    {
        public Form2()
        {
          // 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; 


      ....
          InitializeComponent();
        }

...cut...
Bagman answered 19/8, 2011 at 9:58 Comment(0)
E
0

When you set the form border style to none the form will hide the taskbar. To get around this you have to set the the MaximumSize of the form manually. If windows auto-hides the taskbar the form will cover even the hidden taskbar! To get around this reduce the max size height by one pixel (if your taskbar is in the bottom)!

        Me.MaximumSize = New Size(My.Computer.Screen.WorkingArea.Size.Width, _
                                  My.Computer.Screen.WorkingArea.Size.Height - 1)
Eshman answered 6/3, 2013 at 14:22 Comment(0)
J
0

What I did is the following:

  • Set MaximizeBox property to true
  • Set WindowState to Maximized
  • In constructor of the form, wrote the following:

    this.Bounds = Screen.PrimaryScreen.WorkingArea;

Jowers answered 17/2, 2019 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.