What is the difference between the Control.Enter and Control.GotFocus events?

后端 未结 2 1741
无人及你
无人及你 2021-02-05 01:57

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.

2条回答
  •  庸人自扰
    2021-02-05 03:01

    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.

    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.

提交回复
热议问题