是否以 MDI 表单为重点?

发布于 2024-10-08 23:52:55 字数 212 浏览 3 评论 0原文

到目前为止,我在开发应用程序方面非常幸运。
我的应用程序的主窗体是 MDI 父窗体,直到今晚我才想到在测试中添加任何 MDI 子窗体。
令我惊讶的是,MDI 父级现在似乎永远不会“获得焦点”。 Focus 事件和 OnFocus 方法永远不会被调用!我的意思是......它看起来很集中,但代码内的集中事件/方法都不起作用。相反,MDI 子级会报告焦点。

我该如何解决这个问题?

I've had so much luck developing my application... until now.
My application's main form is a MDI parent, and I didn't think of adding any MDI children in my tests until tonight.
To my surprise, the MDI parent seems to never "get focus" now. The Focus event and the OnFocus method are never called! I mean... it appears focused but none of the in-code focusing events/methods work. Instead a MDI child reports the focus.

How do I fix this?

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

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

发布评论

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

评论(1

花开柳相依 2024-10-15 23:52:55

这是设计使然。窗体充当其他窗口、控件的容器。控件获得焦点,用户与按钮或文本框等进行交互。只有当窗体没有任何控件时它才会获得焦点,只是因为没有其他东西可以获得焦点。一旦您在 MDI 子窗体上放置一个控件,同样的事情就会发生。或者使用Panel 或UserControl、其他容器控件类型。

表单具有激活和停用事件。 ActiveForm 告诉您其中一个当前处于活动状态。请注意主动专注之间的区别。

This is by design. A form acts as a container for other windows, controls. The controls get the focus, the user interacts with, say, a button or text box. Only when the form doesn't have any controls will it get the focus, only because there's nothing else that can get it. The same thing will happen with the MDI child form as soon as you put a control on it. Or with a Panel or UserControl, other container control types.

A form has the Activate and Deactivate events. ActiveForm tells you with one is currently active. Note the distinction between active and focused.

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