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

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

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

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

如何处理上述两个问题的任何建议将不胜感激。

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

更新:上面的代码似乎适用于没有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; } } }