如何在任务栏顶部全屏显示 Windows 窗体?
我有一个 .net windows 应用程序需要全屏运行。然而,当应用程序启动时,任务栏显示在主窗体的顶部,并且仅在通过单击窗体或使用 ALT-TAB 激活窗体时才会消失。表单的当前属性如下:
- WindowState=FormWindowState.Normal
- TopMost=Normal
- Size=1024,768 (这是将要运行的计算机的屏幕分辨率)
- FormBorderStyle = None
我尝试在表单加载时添加以下内容但没有一个对我有用:
- this.Focus(); (给予焦点后 this.Focus 属性始终为 false)
- this.BringToFront();
- this.TopMost = true; (但这在我的场景中并不理想)
- this.Bounds = Screen.PrimaryScreen.Bounds;
- this.Bounds = Screen.PrimaryScreen.Bounds;
有没有办法在 .NET 中做到这一点,或者我是否必须调用本机 Windows 方法,如果是这样,我们将非常感谢代码片段。
非常感谢
I have a .net windows application that needs to run in full screen. When the application starts however the taskbar is shown on top of the main form and it only disappears when activating the form by clicking on it or using ALT-TAB. The form's current properties are as follow:
- WindowState=FormWindowState.Normal
- TopMost=Normal
- Size=1024,768 (this is the screen resolution of the machines it's going to be running on)
- FormBorderStyle = None
I've tried adding the followings on form load but none worked for me:
- this.Focus(); (after giving the focus this.Focus property is always false)
- this.BringToFront();
- this.TopMost = true; (this however would not be ideal in my scenario)
- this.Bounds = Screen.PrimaryScreen.Bounds;
- this.Bounds = Screen.PrimaryScreen.Bounds;
Is there a way to do it within .NET or would I have to invoke native windows methods and if so a code snippet would very much be appreciated.
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
使用:
然后您的表单将放置在任务栏上。
Use:
And then your form is placed over the taskbar.
我已经尝试了很多解决方案,其中一些适用于 Windows XP,而所有这些都不适用于 Windows 7。毕竟我编写了一个简单的方法来执行此操作。
代码的顺序很重要,如果更改 WindwosState 和 FormBorderStyle 的位置,代码的顺序将不起作用。
此方法的优点之一是将 TOPMOST 设置为 false,以允许其他表单优先于主表单。
它绝对解决了我的问题。
I've tried so many solutions, some of them works on Windows XP and all of them did NOT work on Windows 7. After all I write a simple method to do so.
the order of code is important and will not work if you change the place of WindwosState and FormBorderStyle.
One of the advantages of this method is leaving the TOPMOST on false that allow other forms to come over the main form.
It absolutely solved my problem.
这就是我使表单全屏显示的方法。
This is how I make forms full screen.
我的简单修复结果是调用表单的
Activate()
方法,因此不需要使用TopMost
(这就是我的目标)。My simple fix it turned out to be calling the form's
Activate()
method, so there's no need to useTopMost
(which is what I was aiming at).一个经过测试的简单解决方案
我一直在 SO 和其他一些网站中寻找这个问题的答案,但其中一个给出的答案对我来说非常复杂,而其他一些答案根本无法正常工作,因此经过大量代码测试我解决了这个难题。
注意:我使用的是 Windows 8,并且我的任务栏未处于自动隐藏模式。
我发现在执行任何修改之前将 WindowState 设置为“正常”将停止未覆盖任务栏的错误。
我创建这个类的代码
有两个方法,第一个进入“全屏模式”,第二个离开“全屏模式”。因此,您只需创建此类的对象,并将要设置全屏的表单作为参数传递给 EnterFullScreenMode 方法或 LeaveFullScreenMode 方法:
用法示例
我已将相同的答案放在另一个问题上,但我不是确定是否与此重复。 (链接到另一个问题:如何制作WinForms 应用程序进入全屏)
A tested and simple solution
I've been looking for an answer for this question in SO and some other sites, but one gave an answer was very complex to me and some others answers simply doesn't work correctly, so after a lot code testing I solved this puzzle.
Note: I'm using Windows 8 and my taskbar isn't on auto-hide mode.
I discovered that setting the WindowState to Normal before performing any modifications will stop the error with the not covered taskbar.
The code
I created this class that have two methods, the first enters in the "full screen mode" and the second leaves the "full screen mode". So you just need to create an object of this class and pass the Form you want to set full screen as an argument to the EnterFullScreenMode method or to the LeaveFullScreenMode method:
Usage example
I have placed this same answer on another question that I'm not sure if is a duplicate or not of this one. (Link to the other question: How do I make a WinForms app go Full Screen)
我相信只需将 FormBorderStyle 属性设置为 None 并将 WindowState 设置为最大化即可完成此操作。如果您使用的是 Visual Studio,这两个都可以在 IDE 中找到,因此无需以编程方式执行此操作。在执行此操作之前,请确保包含某种关闭/退出程序的方法,因为这将删除右上角的非常有用的 X。
编辑:
试试这个。这是我保存了很长时间的一个片段。我什至不记得该归功于谁,但它确实有效。
I believe that it can be done by simply setting your FormBorderStyle Property to None and the WindowState to Maximized. If you are using Visual Studio both of those can be found in the IDE so there is no need to do so programmatically. Make sure to include some way of closing/exiting the program before doing this cause this will remove that oh so helpful X in the upper right corner.
EDIT:
Try this instead. It is a snippet that I have kept for a long time. I can't even remember who to credit for it, but it works.
我没有解释它是如何工作的,但它是有效的,而成为牛仔编码员就是我所需要的。
I'm not have an explain on how it works, but works, and being cowboy coder is that all I need.
此代码使您的窗口全屏,这也将覆盖整个屏幕
THIS CODE MAKE YOUR WINDOWS FULL SCREEN THIS WILL ALSO COVER WHOLE SCREEN