Control.Leave vs Control.LostFocus

V

vooose

Does anyone know the difference between these two?

The doc for LostFocus says
'Occurs when the control loses focus.'

whereas for Leave it says
'Occurs when the input focus leaves the control'

The doc also states that for controls losing focus you should use Leave,
so I do. Another reason I used it is because comboBox.LostFocus event
was being fired when it gained focus, and then again when it lost focus!


Wal
 
D

Dan Bass

When changing with a mouse, the LostFocus occurs, followed by Leave, then
the validation, making them appear almost synonymous.

The difference is when, according to MSDN, changing Focus of a control by
key press, or progmatically. Leave occurs before any validation, and the
LostFocus after. Almost PreLooseFocus as PostLooseFocus type events.

Use Leave on a control, except, as documentation puts it when checking User
Interface Cues:

"This enumeration is used to specify which user interface cues will be
displayed or changed. For example, when the user presses the ALT key, the
keyboard shortcuts on the menu are displayed by underlining the appropriate
character. The bitwise combination of UICues for this example would be
ShowKeyboard and ChangeKeyboard."
 
L

Liam McNamara

Hi Vooose,

Well one difference is that when the window the control is on loses focus
the LostFocus event is fired whereas the Leave event is only fired when the
cursor leaves the control.

--Liam.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top