【发布时间】:2017-05-28 16:49:43
【问题描述】:
我尝试了How do I make a WinForms app go Full Screen 和How to display a Windows Form in full screen on top of the taskbar 下的所有答案。但它们不能工作(意味着任务栏可见)。
设置 TopMost = true 是一个不好的方法,因为它不能通过 Alt+Tab 切换窗口。
我认为 WindowState = FormWindowState.Maximized 与 AutoSize 冲突。 (我已将 AutoSize 设置为 True,将 AutoSizeMode 设置为 GrowAndShrink 以使其适应面板。)
代码如下(注意FormBorderStyle=和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;
}
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);
}
我正在使用 Windows10。
【问题讨论】:
-
@RezaAghaei 我试过这个解决方案,任务栏也是可见的......
-
您是否尝试过复制
FullScreen属性并将其设置为true的确切代码? -
@RezaAghaei 这就是问题所在。最初在 WindowState.Maximized 中形成。等待 OP 确认以重复关闭
-
@Steve 我将窗口状态设置为
Normal,然后将边框样式设置为None,然后将其设置为Maximized。我没有看到解决方案有任何问题。