What's the difference between Enter and GotFocus?

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm writing a vb.net 2.0 app and am wondering what's the difference between
the Enter and GotFocus events. I know that one fires before the other, but
other than that, what's the difference that would make me choose one over
the other?

Thanks.
 
I'd read up on MSDN about the Control.GotFocus event
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.gotfocus(VS.71).aspx).
There are recommendations from Microsoft as to when GotFocus/LostFocus
should be used vs. when Enter/Leave should be used.

See the below snippet from MSDN....

----

Note The GotFocus and LostFocus events are low-level focus events that are
tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the
GotFocus and LostFocus events are only used when updating UICues. The Enter
and Leave events should be used for all controls except the Form class,
which uses the Activated and Deactivate events. For more information about
the GotFocus and LostFocus events, see the WM_SETFOCUS and WM_KILLFOCUS
topics in the Keyboard Input Reference section of the Platform SDK
Documentation in the MSDN Library.
CAUTION Do not attempt to set focus from within the LostFocus event
handler. Doing so can cause your application or the operating system to stop
responding. For more information about the LostFocus event, see the
WM_KILLFOCUS topic in the Keyboard Input Reference section, and the Message
Deadlocks topic in the Messages and Message Queues section of the Platform
SDK Documentation in the MSDN Library.
 
Hi Moondaddy,

MSDN document about Control.GotFocus event has explained clearly that

"The GotFocus and LostFocus events are low-level focus events that are tied
to the WM_KILLFOCUS and WM_SETFOCUS Windows messages"

and that

"Typically, the GotFocus and LostFocus events are only used when updating
UICues or when writing custom controls".

In other cases, we usually use the Enter event for controls and Activated
event for forms.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Great! Thanks for the info!

Wil Peck said:
I'd read up on MSDN about the Control.GotFocus event
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.gotfocus(VS.71).aspx).
There are recommendations from Microsoft as to when GotFocus/LostFocus
should be used vs. when Enter/Leave should be used.

See the below snippet from MSDN....

----

Note The GotFocus and LostFocus events are low-level focus events that
are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically,
the GotFocus and LostFocus events are only used when updating UICues. The
Enter and Leave events should be used for all controls except the Form
class, which uses the Activated and Deactivate events. For more
information about the GotFocus and LostFocus events, see the WM_SETFOCUS
and WM_KILLFOCUS topics in the Keyboard Input Reference section of the
Platform SDK Documentation in the MSDN Library.
CAUTION Do not attempt to set focus from within the LostFocus event
handler. Doing so can cause your application or the operating system to
stop responding. For more information about the LostFocus event, see the
WM_KILLFOCUS topic in the Keyboard Input Reference section, and the
Message Deadlocks topic in the Messages and Message Queues section of the
Platform SDK Documentation in the MSDN Library.
 
Back
Top