Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使winform应用程序全屏显示并覆盖任务栏_C#_.net_Winforms - Fatal编程技术网

C# 如何使winform应用程序全屏显示并覆盖任务栏

C# 如何使winform应用程序全屏显示并覆盖任务栏,c#,.net,winforms,C#,.net,Winforms,我试过了所有的答案。但是它们不能工作(意味着任务栏可见)。 设置TopMost=true是一种不好的方法,因为它无法通过Alt+Tab切换窗口 我认为WindowsState=FormWindowsState.Maximized与AutoSize冲突。(我已将AutoSize设置为True,将AutoSizeMode设置为Growth和Shrink以使其适应面板。) 下面是代码(注意FormBorderStyle=和WindowsState=的顺序): Designer.cs的代码: priva

我试过了所有的答案。但是它们不能工作(意味着任务栏可见)。
设置TopMost=true是一种不好的方法,因为它无法通过Alt+Tab切换窗口

我认为WindowsState=FormWindowsState.Maximized与AutoSize冲突。(我已将AutoSize设置为True,将AutoSizeMode设置为Growth和Shrink以使其适应面板。)

下面是代码(注意FormBorderStyle=和WindowsState=的顺序):

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上工作。

这是我的全屏和任务栏
(也适用于
AutoSize=true
AutoSizeMode=AutoSizeMode.growthandshrink


换句话说,如果希望获得默认行为,则不要尝试为窗体和面板设置尺寸。相反,强制面板停靠在表单的完整大小内。

这就是我们正在使用的-我们是多屏幕的,所有的面板都是完整的

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
System.Windows.Forms.Screen

但这只是为了得到屏幕的尺寸
您可以使用
Screen获取屏幕。所有屏幕

我在创建新项目时发现任务栏仍然可见,只需使用
this.FormBorderStyle=FormBorderStyle.None;this.WindowState=FormWindowState.Maximized…我不知道这种情况:(尝试添加
this.TopMost=true;
@CodeJoy
this.TopMost=true
将导致它在使用Tab+Alt时无法切换窗口。这并不完美。不知道,但您的任务栏设置可能有点奇怪?右键单击任务栏,然后单击“设置”。@illyrix该问题已根据Rhez发布的副本重现。)aAghaei.如果表单最初在WindowsState中最大化,则任务栏将保持在顶部。尝试将初始WindowsState更改为正常。@RezaAghaei我尝试过此解决方案,任务栏也可见……您是否通过复制
全屏
属性并将其设置为
,尝试了确切的代码?@RezaAghaei这就是问题所在。窗体最初在WindowsState.Maximized中。正在等待OP的确认以作为关闭duplicate@Steve我将窗口状态设置为
Normal
,然后将边框样式设置为
None
,然后使其最大化。我没有发现解决方案有任何问题。我将
此.SystemScreen
替换为
Screen.PrimaryScreen
,但是任务栏也是可见的。如果你点击表单,任务栏会消失吗?
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();
}
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;