gpt4 book ai didi

c# - 全屏 Windows 窗体超越了屏幕尺寸

转载 作者:太空狗 更新时间:2023-10-29 23:13:45 28 4
gpt4 key购买 nike

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

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

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

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

Screenshot of app in maximized mode

更新:上面的代码似乎可以很好地处理没有 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;
}
}
}

关于c# - 全屏 Windows 窗体超越了屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32821133/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com