全屏Windows窗体超出屏幕尺寸 [英] Full screen Windows Form goes beyond screen dimensions
问题描述
我有需要显示全屏或无边框最大化WinForms应用程序(.NET 4)。
I have a WinForms app (.NET 4) that needs to be shown either full screen or maximized without borders.
在<$ c使用下面的代码$ C> 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.
<一个HREF =http://i.stack.imgur.com/fuk06.png相对=nofollow>
更新:上面的代码似乎没有<$ C $与形式,做工精细C>的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窗体超出屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!