c# – 为什么在不同的时间调用LostFocus事件?

前端之家收集整理的这篇文章主要介绍了c# – 为什么在不同的时间调用LostFocus事件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
关于 this MSDN page(或任何相关页面),它指出:

When you change the focus by using the keyboard,focus events occur in
the following order:

  1. Enter@H_404_8@
  2. GotFocus@H_404_8@
  3. Leave@H_404_8@
  4. Validating@H_404_8@
  5. Validated@H_404_8@
  6. LostFocus@H_404_8@

但是,当您使用鼠标引发事件时,订单更改!

When you change the focus by using the mouse or by calling the Focus method,focus events occur in the following order:

  1. Enter@H_404_8@
  2. GotFocus@H_404_8@
  3. LostFocus@H_404_8@
  4. Leave@H_404_8@
  5. Validating@H_404_8@
  6. Validated@H_404_8@

这不会使事件链完全不同吗?我的解释是,键盘链确保一切正常工作,然后引发LostFocus事件.然而,鼠标事件似乎在由于某种原因进行验证之前提高了.这是为什么?

解决方法

我可以想到的最好的例子是验证中的e.Cancel方面.使用键盘进行导航通常是控制导航类型(包括子级和父级控件).使用鼠标进行表单导航并不总是导致选择控件.例如关闭表单或只需单击控件外(即重新定位表单).当控件外部发生鼠标点击时,并不总是希望进行验证.希望有帮助.

猜你在找的C#相关文章