是否以 MDI 表单为重点?
到目前为止,我在开发应用程序方面非常幸运。
我的应用程序的主窗体是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设计使然。窗体充当其他窗口、控件的容器。控件获得焦点,用户与按钮或文本框等进行交互。只有当窗体没有任何控件时它才会获得焦点,只是因为没有其他东西可以获得焦点。一旦您在 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.