How can I prevent other apps from stealing the focus?

我的未来我决定 提交于 2019-12-01 04:13:32

问题


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.


回答1:


You may want to investigate "Kiosk Mode".




回答2:


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




回答3:


Perhaps this is what you want: Windows Form in Full Screen "Kiosk Mode".

Otherwise I'll second Henk's recomendation.



来源:https://stackoverflow.com/questions/2086477/how-can-i-prevent-other-apps-from-stealing-the-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!