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.