在客户区中单击时,MDI 子窗体不会激活

发布于 2024-09-11 17:25:19 字数 372 浏览 6 评论 0原文

我的 VB.NET 应用程序支持多种 MDI 子窗体。有些类型是“麻烦”的,但其他类型则不然——它们会导致聚焦机制变得奇怪。一旦打开“麻烦的”子窗体,除非我单击标题栏或边框,否则任何 MDI 子窗体都不会被激活。单击客户区不会激活子窗体——它的标题栏保持灰色,并且不会接收 Activate 或 GotFocus 事件。然而,奇怪的是,单击的窗体实际上确实接收了焦点,因为它的控件接收鼠标和按键事件。只有 Z 顺序和突出显示不会改变。

一旦出现此问题,即使在“麻烦”表单关闭后它仍然存在,并且会影响随后打开的子表单。但是,如果所有子表单都关闭,问题就会消失,新的子表单将正常运行,直到出现下一个“麻烦”表单。

我不知道为什么一种儿童形式很麻烦,而另一些则不然。

任何建议将不胜感激。

My VB.NET app supports several kinds of MDI child forms. Some kinds, but not others, are 'troublesome' -- they cause the focus mechanism to become weird. Once a 'troublesome' child form has been opened, NONE of the MDI child forms will become activated unless I click on either the title bar or the border. Clicking in the client area does not activate the child form -- its title bar remains gray, and it does not receive Activate or GotFocus events. Strangely, however, the clicked-on form actually DOES receive the focus, because its controls receive mouse and key events. Only the Z-Order and the highlighting do not change.

Once this problem develops, it persists even after the 'troublesome' form is closed, and it affects child forms which are opened afterward. However, if ALL of the child forms are closed, the problem clears up, and new child forms behave normally -- until the next 'troublesome' form appears.

I have no idea why one kind of child form is troublesome, and others are not.

Any suggestions would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2024-09-18 17:25:19

我进入这个领域有点晚了,但我也遇到了上述相同的症状。我也有一些表格导致了这个问题,而其他表格则没有。

我找到了一个解释问题的链接,并将该概念应用到我的表单中。

http ://www.pcreview.co.uk/forums/mdi-child-forms-functionity-does-not-work- Correctly-

windows-f-t2894221.html 它基本上与确保forms MdiParent 在导致创建窗体窗口的任何代码(对 CreateWindow() 或 CreateWindoEX() 的 API 调用)之前设置。无论如何,我发现我的一些窗口在构造函数中包含导致创建 API 窗口的代码。一个示例是带有 WebBrowser 控件的表单。我将一个 URL 传递到构造函数的表单中,构造函数又将其传递到 WebBrowser.Navigate 方法中。在这种情况下,我的 MdiChild 窗口不会按预期激活。我更改了构造函数,使其保存了 URL,并覆盖了表单的 CreateHandle 方法,以便尽早在 WebBrowser 中实际设置 URL。表单现在按预期激活。

  private string _URL = "";

  public frmReportServer(String URL, String Title) : this() {
     _URL = URL;
     this.Text = Title;
  }

  protected override void CreateHandle() {
     base.CreateHandle();
     if (_URL != "") wbReports.Navigate(URL, false);
  }

希望这有帮助...

I am a little late getting into this but I was experiencing the same symptoms described above. I too had a few forms that caused this issue and others that didn't.

I found a link that explains the problem and applied the concept to my forms.

http://www.pcreview.co.uk/forums/mdi-child-forms-functionality-does-not-work-correctly-windows-f-t2894221.html

It basically has to do with making sure that the forms MdiParent is set before any code that causes the form's window to be created (the API call to CreateWindow() or CreateWindoEX()). Anyway I found a few of my windows had code in the Constructors that caused the API window to be created. An example of this was a form with a WebBrowser control on it. I passed a URL into the form on the Constructor which in turned passed it into the WebBrowser.Navigate method. In this scenario, my MdiChild windows would not activate as expected. I changed the Constructor such that it saved the URL and also overrode the form's CreateHandle method to actually set the URL in the WebBrowser at the earliest possible time. The forms now activate as expected.

  private string _URL = "";

  public frmReportServer(String URL, String Title) : this() {
     _URL = URL;
     this.Text = Title;
  }

  protected override void CreateHandle() {
     base.CreateHandle();
     if (_URL != "") wbReports.Navigate(URL, false);
  }

Hope this helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文