Control.Enter和Control.GotFocus事件之间有什么区别? [英] What is the difference between the Control.Enter and Control.GotFocus events?

查看:79
本文介绍了Control.Enter和Control.GotFocus事件之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个基本问题,但是我不得不承认,我从未真正理解过Control.Enter和Control.GotFocus事件之间的区别.

This may be a basic question, but I have to admit I've never truly understood what the difference between the Control.Enter and Control.GotFocus events is.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enter.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx

捕获键盘或鼠标输入或其他东西有区别吗?

Is it a differentiation between capturing keyboard or mouse input or something else?

推荐答案

GotFocus/LostFocus事件分别由Windows消息WM_SETFOCUS和WM_KILLFOCUS生成.它们有点麻烦,尤其是WM_KILLFOCUS容易陷入僵局.Windows窗体内部处理验证逻辑(例如,Validating事件)的逻辑可以覆盖焦点更改.换句话说,焦点实际上发生了变化,但随后验证代码将其移回了原处.用户界面的逻辑状态是它永远不会移动,并且您不应该知道它已经移动.

The GotFocus/LostFocus events are generated by Windows messages, WM_SETFOCUS and WM_KILLFOCUS respectively. They are a bit troublesome, especially WM_KILLFOCUS which is prone to deadlock. The logic inside Windows Forms that handles the validation logic (Validating event for example) can override focus changes. In other words, the focus actually changed but then the validation code moved it back. The logical state of your UI is that it never moved and you shouldn't be aware that it did.

Enter/Leave事件避免了这些低级别的焦点更改通知事件可能导致的麻烦,它们是在Winforms建立真正的焦点时生成的.您几乎总是想使用这些.

The Enter/Leave events avoid the kind of trouble these low-level focus change notification events can cause, they are generated when Winforms has established the true focus. You almost always want to use these.

这篇关于Control.Enter和Control.GotFocus事件之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆