全屏Windows窗体超出了屏幕尺寸

Rah*_*han 5 .net c# fullscreen winforms

我有一个WinForms应用程序(.NET 4),需要全屏显示或最大化显示而没有边框。

Form_Shown事件中使用以下代码:

#if (DEBUG)
    var debug = true;
#else
    var debug = false;
#endif

this.Text = "";
this.ControlBox = false;
this.ShowInTaskbar = true;
//this.TopMost = debug;
this.TopLevel = true;
this.FormBorderStyle = FormBorderStyle.None;

if (debug) { this.Bounds = Screen.FromControl(this).WorkingArea; }
else { this.WindowState = FormWindowState.Maximized; }
Run Code Online (Sandbox Code Playgroud)

如果您仔细查看下面的屏幕截图,顶部和底部区域将被剪切几个像素。同样,如果最大化,该窗口仍不会覆盖任务栏。

请注意,我仅连接了一台显示器。没有辅助显示。

关于如何解决上述两个问题的任何建议将不胜感激。

最大化模式下的应用屏幕截图

更新:上面的代码似乎适用于不带MenuStripor的表单StatusStrip

Rez*_*aei 5

这是我用于全屏显示的代码。我FullScreen为表单创建一个属性,并在需要时设置this.FullScreen = true;

private bool fullScreen = false;
[DefaultValue(false)]
public bool FullScreen
{
    get
    {
        return fullScreen;
    }
    set
    {
        fullScreen = value;

        if (value)
        {
            //this.SuspendLayout();
            this.WindowState = FormWindowState.Normal;
            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            //this.ResumeLayout(true);
        }
        else
        {
            this.Activate();
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)