简体   繁体   English

为什么隐藏拥有的窗口会在WinForms(.NET)中切换应用程序?

[英]Why does hiding an owned window switches app in WinForms (.NET)?

I have an application window which covers the screen and there are several minor tool windows which are hidden by default and their 'Owner' properties are set to this main window. 我有一个覆盖屏幕的应用程序窗口,默认情况下隐藏了几个小工具窗口,它们的“所有者”属性设置为此主窗口。

When I show a tool window and click one of its buttons it hides itself to show another window. 当我显示一个工具窗口并单击其中一个按钮时,它会隐藏自己以显示另一个窗口。 When I hide that another tool window Windows switches app just like when you press alt+tab. 当我隐藏另一个工具窗口时Windows切换应用程序就像按下alt + tab一样。 The only way to prevent this is clicking on the main application window before closing (hiding) the tool window. 防止这种情况的唯一方法是在关闭(隐藏)工具窗口之前单击主应用程序窗口。

Why does the application switching happens and how to prevent this? 为什么应用程序切换发生以及如何防止这种情况? Well I can tell explicitly those windows to bring the main window front on hide (I haven't tried that yet, but I don't like to do that.) This only happens when the Owner property is set on the that windows to prevent them from showing behind the main window. 好吧,我可以明确告诉那些窗口将主窗口置于隐藏状态(我还没有尝试过,但我不喜欢这样做。)这只发生在那个窗口上设置所有者属性以防止它们显示在主窗口后面。

ps: This full screen app is a game and those windows are the menus and the setting screens etc... ps:这个全屏应用程序是一个游戏,那些窗口是菜单和设置屏幕等...

Murky problem, I can't repro and haven't heard of this before. 黑暗的问题,我不能责备,也没有听过这个。 This behavior is normal when the Windows window manager is forced to hunt for another window to give the focus to when the current one closes. 当Windows窗口管理器被强制寻找另一个窗口以在当前关闭时关注焦点时,此行为是正常的。 And the app doesn't have any window left that is enabled. 该应用程序没有任何启用的窗口。 That should not be the case in your app, unless you intentionally set your main window's Enable property to False if the tool window gets the focus. 除非您在工具窗口获得焦点时故意将主窗口的Enable属性设置为False,否则应该不是您的应用中的情况。 Running windows on different threads is a long-shot explanation. 在不同的线程上运行窗口是一个长期的解释。

Things to try are to set the tool window's ShowInTaskbar property to false so the user must always go through the main window to refocus the app. 要尝试的是将工具窗口的ShowInTaskbar属性设置为false,以便用户必须始终通过主窗口重新聚焦应用程序。 And to make sure the window only closes due to a MouseUp event so mouse capture can't mess things up. 并确保窗口仅因MouseUp事件而关闭,因此鼠标捕获无法解决问题。 And, yes, to explicitly focus the main window in the FormClosing event. 并且,是的,明确地将主窗口集中在FormClosing事件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM