我有需要显示全屏或无边框最大化WinForms应用程序(.NET 4)。
I have a WinForms app (.NET 4) that needs to be shown either full screen or maximized without borders.
在 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; }如果您在下面的截图仔细观察,顶部和底部区域由几个切断像素。另外,如果最大化,窗口仍然不包括任务栏。
If you look closely at the screenshot below, the top and bottom areas are cut off by a few pixels. Also, if maximized, the window still does not cover the task bar.
请注意,我只有一台显示器连接。无二次显示器。
Please note that I have only one monitor attached. No secondary displays.
如何解决这两个问题上面,将不胜感激任何建议。
Any suggestions on how to address the two issues above would be appreciated.
更新:上面的代码似乎没有的MenuStrip 或 StatusStrip中。
UPDATE: The code above seems to work fine with forms without a MenuStrip or StatusStrip.
推荐答案这是我使用全屏的代码。我创建了一个全屏属性我的形式,当我需要,我将 this.FullScreen = TRUE;
Here is the code I use for fullscreen. I create a FullScreen property for my form and when I need, I set 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; } } }更多推荐
全屏Windows窗体超出屏幕尺寸
发布评论