简体   繁体   English

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

[英]how to make a winform application fullscreen and cover taskbar

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 .我尝试了如何使 WinForms 应用程序全屏显示如何在任务栏顶部全屏显示 Windows 窗体下的所有答案。 But they cannot work (means the taskbar is visible).但它们不能工作(意味着任务栏是可见的)。
Setting TopMost = true is a bad way because it cannot switch windows by Alt+Tab.设置 TopMost = true 是一种糟糕的方式,因为它无法通过 Alt+Tab 切换窗口。

I thought WindowState = FormWindowState.Maximized is conflicted with AutoSize.我认为 WindowState = FormWindowState.Maximized 与 AutoSize 冲突。 (I have set AutoSize to True, and AutoSizeMode to GrowAndShrink to make it adapt to a panel.) (我已将 AutoSize 设置为 True,将 AutoSizeMode 设置为 GrowAndShrink 以使其适应面板。)

Here's code (note the order of FormBorderStyle= and WindowState=):这是代码(注意 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;
}

the code of Designer.cs: 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.我正在使用 Windows10。

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

but it's just to get the dimension of the screen You can get your screens with Screen.AllScreens但这只是为了获取屏幕的尺寸您可以使用Screen.AllScreens获取屏幕

This goes full screen and over the taskbar for me这对我来说是全屏和任务栏上的
(also with AutoSize = true and AutoSizeMode = AutoSizeMode.GrowAndShrink ) (还有AutoSize = trueAutoSizeMode = 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.而是强制面板停靠在窗体的全尺寸内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM