1

I tried all answers under How do I make a WinForms app go Full Screen and How to display a Windows Form in full screen on top of the taskbar. But they cannot work (means the taskbar is visible).
Setting TopMost = true is a bad way because it cannot switch windows by Alt+Tab.

I thought WindowState = FormWindowState.Maximized is conflicted with AutoSize. (I have set AutoSize to True, and AutoSizeMode to GrowAndShrink to make it adapt to a panel.)

Here's code (note the order of FormBorderStyle= and WindowState=):

public void fullScreenDisplay()
{
    this.currentPanelSize = new Size(this.mainPanel.ClientSize.Width, this.mainPanel.ClientSize.Height);

    this.FormBorderStyle = FormBorderStyle.None;
    //this.TopMost = true;
    //Rectangle ret = Screen.GetWorkingArea(this);
    Rectangle ret = Screen.PrimaryScreen.Bounds;

    this.mainPanel.ClientSize = new Size(ret.Width, ret.Height);
    //this.mainPanel.Dock = DockStyle.Fill;
    this.mainPanel.BringToFront();

    this.WindowState = FormWindowState.Maximized;
}

the code of Designer.cs:

private void InitializeComponent()
{ 
    this.mainPanel = new System.Windows.Forms.Panel();
    this.SuspendLayout();
    // 
    // mainPanel
    // 
    this.mainPanel.Location = new System.Drawing.Point(0, 0);
    this.mainPanel.Margin = new System.Windows.Forms.Padding(0);
    this.mainPanel.Name = "mainPanel";
    this.mainPanel.Size = new System.Drawing.Size(1600, 900);
    this.mainPanel.TabIndex = 0;
    this.mainPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.mainPanel_Paint);
    // 
    // MainForm
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.AutoSize = true;
    this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    this.ClientSize = new System.Drawing.Size(120, 0);
    this.Controls.Add(this.mainPanel);
    this.MaximizeBox = false;
    this.Name = "MainForm";
    this.Text = "MainForm";
    this.Load += new System.EventHandler(this.MainForm_Load);
    this.ResumeLayout(false);

}

And I'm working on Windows10.

Community
  • 1
  • 1
illyrix
  • 153
  • 2
  • 11
  • 1
    [Full screen Windows Form goes beyond screen dimensions](http://stackoverflow.com/a/32821243/3110834). – Reza Aghaei Jan 13 '17 at 11:28
  • @RezaAghaei I've tried this solution and the taskbar is also visible... – illyrix Jan 13 '17 at 11:36
  • Did you try the exact code by copying the `FullScreen` property and setting it to `true`? – Reza Aghaei Jan 13 '17 at 11:41
  • @RezaAghaei that's the problem. Form initially in WindowState.Maximized. Waiting a confirm from the OP to close as duplicate – Steve Jan 13 '17 at 11:43
  • @Steve I set window state to `Normal` and then border style to `None` and then make it `Maximized`. I've not seen any problem with the solution. – Reza Aghaei Jan 13 '17 at 11:46
  • @RezaAghaei I've tried... but it have no effect...the form is NOT maximized before `fullScreenDisplay()` – illyrix Jan 13 '17 at 11:48
  • Yes, I mean, probably the OP has the WindowState Maximized from the designer but it doesn't set it back to normal – Steve Jan 13 '17 at 11:48

2 Answers2

1

This is what we are using - we are multi-screen and all of them are full covering taskbar

mainForm.WindowState = FormWindowState.Normal;
mainForm.FormBorderStyle = FormBorderStyle.Sizable;
mainForm.StartPosition = FormStartPosition.Manual;
mainForm.Location = this.SystemScreen.Bounds.Location;
mainForm.FormBorderStyle = FormBorderStyle.None;
mainForm.Size = this.SystemScreen.Bounds.Size;
mainForm.WindowState = FormWindowState.Maximized;

SystemScreen is System.Windows.Forms.Screen

but it's just to get the dimension of the screen You can get your screens with Screen.AllScreens

Ofir Winegarten
  • 9,215
  • 2
  • 21
  • 27
0

This goes full screen and over the taskbar for me
(also with AutoSize = true and AutoSizeMode = AutoSizeMode.GrowAndShrink)

public void fullScreenDisplay()
{
    // This is required if the form reaches this code in maximized state
    // otherwise the TaskBar remains on top of the form
    this.WindowState = FormWindowState.Normal;

    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
    this.mainPanel.Dock = DockStyle.Fill;
    this.BringToFront();
}

In other words, don't try to set the dimensions neither for the form and for the panel if you want the get the default behavior. Instead force the Panel to Dock inside the full size of the form.

Steve
  • 213,761
  • 22
  • 232
  • 286
  • I found the taskbar is still visible when i create a new project and just use `this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized;` ...I have no idea about this situation :( – illyrix Jan 13 '17 at 11:26
  • Try adding `this.TopMost = true;` – Pepernoot Jan 13 '17 at 11:33
  • @CodeJoy `this.TopMost = true` will cause it cannot switch window when using Tab+Alt. That's not perfect. – illyrix Jan 13 '17 at 11:39
  • No idea, but perhaps something odd in your TaskBar settings? Right Click on the TaskBar and then Settings. – Steve Jan 13 '17 at 11:41
  • @illyrix The problem has been reproduced according to the duplicate posted by RhezaAghaei. If the form is initially in WindowState Maximized the TaskBar remains on top. Try to change the initial WindowState to Normal – Steve Jan 13 '17 at 11:45
  • I use the same code you post but also not effective...and the Taskbar setting is the default value, i haven't changed them. – illyrix Jan 13 '17 at 11:57
  • I have no more ideas. Or there is something not standard in your system or there is something else at play in your code. As you have seen everyone recommends these settings. You could try to build a new project with just the same elements. I can also suggest to try your code using LinqPad to try different combinations of these settings but I am afraid that none of this is conclusive. Also take a strict look to every settings made in the designer and check to revert something there. And look if you change them somewhere in code. – Steve Jan 13 '17 at 12:15
  • @Steve i'll try to test on win7 later..I guess there is something different on my system or environment from others .. – illyrix Jan 13 '17 at 12:35