全屏 Windows 表单超出屏幕尺寸

Full screen Windows Form goes beyond screen dimensions

我有一个 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; }

如果您仔细观察下面的屏幕截图,您会发现顶部和底部区域被切掉了几个像素。此外,如果最大化,window 仍然不会覆盖任务栏。

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

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

更新: 上面的代码似乎可以很好地处理没有 MenuStripStatusStrip.

的表单

这是我用于全屏的代码。我为我的表单创建了一个 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;
        }
    }
}