美好的一天,我有一个可以设置全屏的winform。但有时它并非如此。它有时是屏幕的3/4,但有时它是全屏的。以下是我的代码。有人知道为什么它不总是全屏....?
private void Form1_Load(object sender, EventArgs e)
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
Width = Screen.PrimaryScreen.WorkingArea.Width;
Height = Screen.PrimaryScreen.WorkingArea.Height;
}
当我在电脑上运行时。没关系。但是当它在生产中。我看到它进展不顺利。但有时候还可以。
顺便说一句,我希望看到我的任务栏。如果我设置FormWindowState.Maximized,我的任务栏将不会被看到。
谢谢。
答案 0 :(得分:1)
问题是WorkingArea
与全屏不同。 WorkingArea
是相对的,而不是强制全屏的常见方式。
有几种方法可以尝试强制全屏。
强制填充的最常用方法之一是设置WindowsState to Maximized(同时here和here - 非常受欢迎)并将TopMost
属性设置为{{1 }}
true
或者,不那么普遍,您也可以使用Screen.Bounds(但也可能不是绝对的,尝试添加额外的private void Form1_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
)
最后,您还可以将TopMost = true
与条件语句一起使用。要调试并查看生产PC中的WorkingArea
大小,可以使用GetWorkingArea方法。这样,您可以调试生产PC中的工作区域,如果它不是全屏,则与PC的大小相比,您可以强制全屏显示。虽然效率不高......
以下是working area vs screen area的更多解释,以帮助您做出决定。
编辑:要看到栏,我能想到的另一种方法是通过获取屏幕尺寸。参见:
How can I get the active screen dimensions?
然后你应该限制你的表格的最大尺寸(y / x轴),这样你的酒吧就有空间 - 也就是说,要比其中一个轴的屏幕尺寸小一点。然后,在表单加载或其他相关事件上,您可以控制WinForm的位置,以便您不会阻止您的栏。
请参阅StartupPosition属性:
答案 1 :(得分:0)
Screen.PrimaryScreen.WorkingArea
只能访问屏幕的工作区域。
我认为您需要将其更改为
Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height;
答案 2 :(得分:0)
您只需要在运行时将WindowState设置为Maximized:
WindowState = FormWindowState.Maximized;
或者在设计时,使用表单的WindowState属性。