如何防止其他应用程序抢走焦点?
我有一个全屏窗口,其 Topmost 属性设置为 true。每当应用程序更改其 WindowState 属性时,即使我的窗口具有活动焦点,它也会自动最小化。例如,下面的代码就说明了该问题。窗口停用 3 秒后,它会从最小化变为正常,从而最小化其他全屏应用程序。
// Topmost = false
private void Form1_Deactivate(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
this.WindowState = FormWindowState.Normal;
}
在这种情况下有没有办法保留全屏窗口的 WindowState 属性?我希望用户选择最小化全屏应用程序,因此我想阻止其他程序窃取焦点。
I have a fullscreen window with the Topmost property set to true. Whenever an application changes its WindowState property, my window is automatically minimized even though it has the active focus. For example, the code below exemplifies the problem. 3 seconds after the window is deactivated, it changes from Minimized to Normal, minimizing the other fullscreen application.
// Topmost = false
private void Form1_Deactivate(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
this.WindowState = FormWindowState.Normal;
}
Is there a way to preserve the fullscreen window's WindowState property in such a case? I want the user to choose to minimize the fullscreen app, so I want to stop other programs from stealing the focus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要研究一下“信息亭模式”。
You may want to investigate "Kiosk Mode".
如果这是一个信息亭应用程序,并且您是计算机上运行的唯一程序,那么很好。否则,这是一个非常糟糕的主意,这就是为什么没有记录的方法来做到这一点。
正如 Raymund Chen 所说,此类问题应该进行思想实验“如果两个程序执行此操作会怎样?”:
http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx
If this is a kiosk application and you are the only program running on the computer then fine. Otherwise this is a really bad idea and that's why there is not a documented way of doing it.
As Raymund Chen says this kind of question should be followed with the thought experiment "what if two programs did this?":
http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx
也许这就是您想要的: Windows 窗体全屏“Kiosk”模式”。
否则我会赞同亨克的建议。
Perhaps this is what you want: Windows Form in Full Screen "Kiosk Mode".
Otherwise I'll second Henk's recomendation.