全屏Windows窗体超出屏幕尺寸

编程入门 行业动态 更新时间:2024-10-13 06:18:56
本文介绍了全屏Windows窗体超出屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有需要显示全屏或无边框最大化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窗体超出屏幕尺寸

本文发布于:2023-10-08 01:14:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471081.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   全屏   屏幕尺寸   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!