GotFocus() 和 MDI 子项

发布于 2024-09-09 07:14:15 字数 302 浏览 12 评论 0原文

我有一个带有 3 个子窗口的 MDI 表单。

  • MDI 开始为空。

  • 每个子项都可以从菜单中打开一次。

当我打开多个窗口并关闭顶部窗口时,应该获得焦点,但新的活动子窗体的 GotFocus() 事件未触发。

Private Sub frmMain_gotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
...
End Sub

I have an MDI form with 3 child windows.

  • The MDI starts empty.

  • Each child can be opened once from the menu.

When I open multiple windows, and close the top one should get focus, but the new active child-form's GotFocus() event is not firing.

Private Sub frmMain_gotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
...
End Sub

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

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

发布评论

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

评论(2

许仙没带伞 2024-09-16 07:14:15

不幸的猜测。 Enter 或 Activated 事件都可以解决您的问题。

在 Windows 窗体编程中,您通常希望避免 GotFocus 和 LostFocus 事件。它们通常隐藏在设计器中,但并不始终如一。 Enter 和 Leave 事件分别是它们的替代品,它们是根据 UI 的逻辑状态而不是原始 Windows 消息生成的。使用验证和 MDI 时会有所不同。

激活是“自然”的,因为实际焦点移动到该形式的子控件。

Unlucky guess. Either the Enter or the Activated event will solve your problem.

In Windows Forms programming, you'd typically want to avoid the GotFocus and LostFocus events. They are often hidden in the designer, but not consistently. Respectively, the Enter and Leave events are their replacements, they are generated from the logical state of the UI instead of the raw Windows messages. Makes a difference when using Validating and MDI.

Activated is the "natural" one since the actual focus moves to a child control of that form.

自我难过 2024-09-16 07:14:15

当您从 MDI 父窗体创建 MDI 子窗体时,您应该将 MDI 父窗体订阅到 MDI 子窗体的 GotFocus 事件。当您的 MDI 子级发生任何焦点事件时,您的 MDI 父级会收到通知。

当关闭/打开窗体时,应自动选择 MDI Z 顺序中的下一个子窗体,并且如果您订阅该事件,您的 MDI 父窗体可以采取适当的操作并显示您的数据。

When you create the MDI children forms from the MDI parent, you should subscribe the MDI parent form to the MDI child form's GotFocus event. That when any focus events happen on your MDI Child, your MDI Parent gets notified.

When a form is closed/opened, the next child form in the MDI Z-Order should automatically be selected, and if you're subscribing to the event, your MDI parent can act appropriately and display your data.

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