简体   繁体   English

如何防止其他应用窃取焦点?

[英]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.

相关问题 如何在仍然接收鼠标点击时阻止表单窃取焦点? - How can I prevent a form from stealing focus while still receiving mouse clicks? 如何防止用户控件窃取焦点? - How to prevent user control from stealing focus? 如何防止单个MDI子窗体窃取其他所有MDI子窗体的焦点 - how to prevent a single MDI child form stealing focus from every other mdi child form 当我将可见的正确设置为true时,如何防止我的C#winforms应用程序窃取焦点? - How to prevent my C# winforms application from stealing focus when I set the visible properly to true? C#ChromiumWebBrowser:防止控制窃取焦点 - C# ChromiumWebBrowser: Prevent control from stealing focus 如何阻止按钮窃取按键事件? - How can I stop a button from stealing my keypress event? 我如何防止另一个程序的特定窗口窃取焦点(C#?) - how do i keep a specific window of another program from stealing focus (C# ?) 如何防止RadioGroup尝试在Focus上设置SelectedItem? - How can I prevent a RadioGroup from trying to set SelectedItem on Focus? 如何临时阻止表单获得焦点/激活? - How can I temporarily prevent a form from getting focus/activating? 如何在插入图像时防止Excel互操作窃取焦点 - How to keep Excel interop from stealing focus while inserting images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM