[英]How can I prevent other apps from stealing the focus?
I have a fullscreen window with the Topmost property set to true. 我有一个全屏窗口,其中Topmost属性设置为true。 Whenever an application changes its WindowState property, my window is automatically minimized even though it has the active focus.
每当应用程序更改其WindowState属性时,我的窗口都会自动最小化,即使它具有活动焦点。 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.
停用窗口3秒钟后,它从“最小化”变为“正常”,从而最小化了其他全屏应用程序。
// 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? 在这种情况下,是否可以保留全屏窗口的WindowState属性? I want the user to choose to minimize the fullscreen app, so I want to stop other programs from stealing the focus.
我希望用户选择最小化全屏应用程序,因此我想阻止其他程序窃取焦点。
您可能需要调查“信息亭模式” 。
Perhaps this is what you want: Windows Form in Full Screen "Kiosk Mode" . 也许这就是您想要的: 全屏“ Kiosk模式”下的Windows窗体 。
Otherwise I'll second Henk's recomendation. 否则,我将第二次推荐Henk。
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?":
正如雷蒙德·陈(Raymund Chen)所说的那样,应该在思想实验之后提出“如果两个程序这样做,该怎么办?”:
http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.