简体   繁体   English

为什么LostFocus事件会在不同时间被调用?

[英]Why does the LostFocus event get called at different times?

In reference to this MSDN page (or any related page on the matter), it states that: 在参考此MSDN页面 (或关于此事项的任何相关页面)时,它指出:

When you change the focus by using the keyboard, focus events occur in the following order: 使用键盘更改焦点时,焦点事件按以下顺序发生:

  1. Enter 输入
  2. GotFocus 的GotFocus
  3. Leave 离开
  4. Validating 证实
  5. Validated 验证
  6. LostFocus 引发LostFocus

However, when you use the mouse to raise events, the order changes! 但是,当您使用鼠标来引发事件时,订单会发生变化!

When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order: 使用鼠标或通过调用Focus方法更改焦点时,焦点事件按以下顺序发生:

  1. Enter 输入
  2. GotFocus 的GotFocus
  3. LostFocus 引发LostFocus
  4. Leave 离开
  5. Validating 证实
  6. Validated 验证

Wouldn't this make the chain of events completely different? 这不会使事件链完全不同吗? My interpretation here is that the keyboard chain ensures everything is in working order, then raises the LostFocus event. 我的解释是键盘链确保一切正常,然后引发LostFocus事件。 Yet, the mouse events seem to raise it before validating for some reason. 然而,鼠标事件似乎在出于某种原因进行验证之前提高了它。 Why is that? 这是为什么?

As noted above: 如上所述:

In the MSDN article you linked worded strong enough? 在MSDN文章中你链接的措辞足够强大? Never use LostFocus, only Leave. 永远不要使用LostFocus,只留下。

The keyboard navigation must be in this order in order to apply the validations. 键盘导航必须按此顺序才能应用验证。 Those are intended to react to them in order to validate any input strings. 这些是为了对它们作出反应以验证任何输入字符串。

The best example I can think of is the e.Cancel aspect in validation. 我能想到的最好的例子是验证中的e.Cancel方面。 Using the keyboard for navigation is usually a control to control type of navigation (including child and parent controls). 使用键盘进行导航通常是控制导航类型(包括子控件和父控件)的控件。 Using the mouse for form navigation does not always result in a control being selected. 使用鼠标进行表单导航并不总是导致选择控件。 For example closing a form or simply click outside of the control (ie re-positioning the form). 例如,关闭表单或只是单击控件外部(即重新定位表单)。 It is not always desirable to have the validation occur when a mouse click occurs outside a control. 在控件外部发生鼠标单击时,并不总是希望进行验证。 Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM