简体   繁体   English

子窗体失去对父窗体的第一次单击的关注。 如何解决这个问题?

[英]Child form loses focus on first click to parent form. How to fix this?

Im writing a new plugin based app. 我正在写一个新的基于插件的应用程序。 This loads assemblies in their own app domains and displays the specified main forms within each via Application.Run(pluginForm). 这会将程序集加载到其自己的应用程序域中,并通过Application.Run(pluginForm)在每个应用程序域中显示指定的主要表单。 I set the main form in the loader app as the parent of each pluginForm before calling Application.Run(pluginForm) inside the app domain. 在调用应用程序域内的Application.Run(pluginForm)之前,我将加载器应用程序中的主窗体设置为每个pluginForm的父窗体。 Hence when the pluginForm shows it always gets displayed in front of the mainForm of the loader app. 因此,当pluginForm显示时,它总是显示在加载器应用程序的mainForm前面。

My problem is when a user clicks for the first time on the pluginForm (child form), it looses focus and the mainForm (loader app's form) gets focus. 我的问题是,当用户第一次单击pluginForm(子窗体)时,它失去了焦点,而mainForm(加载器应用程序的窗体)获得了焦点。 (However the pluginForm stays in front) Hence the user ends up having to click twice to get the pluginForm to focus for the first time. (但是pluginForm始终位于最前面),因此用户最终不得不单击两次以使pluginForm首次聚焦。

This is pretty annoying. 这很烦人。 How can I fix this? 我怎样才能解决这个问题?

您应该通过调用ShowDialog()将子表单显示为父UI线程上的模式对话框。

When you call the child Forms use 当您调用子窗体使用时

childForm.ShowDialog(parentForm);

OR the equivalent 或同等学历

childForm.ShowDialog(this);

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

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