Maximized screen ignores taskbar

送分小仙女□ 提交于 2019-11-29 13:34:38

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.

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.

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?

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)

Mostafa Zare

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

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

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)
Davronbek Rahmonov

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;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!