views:

32

answers:

2

I wanted to add an event for a textbox to handle when it loses focus. I was sure I remembered some sort of LostFocus event, but I didn't see it in the Properties grid. But sure enough, the event exists if I access it programmatically. I'm using VS2008 - any reason why this event (and maybe others?) wasn't shown in the Properties grid?

+6  A: 

Control.LostFocus is marked with [BrowsableAttribute(false)]. This means it will not be shown in the Properties window. For details see BrowsableAttribute.

Here's the declaration:

[BrowsableAttribute(false)]
public event EventHandler LostFocus
Jason
+1 I'm curious to know why? Is it because they want us to use Enter and Leave instead?
Coincoin
+1  A: 

LostFocus is a troublesome event, this is the fine print from the SDK docs for WM_KILLFOCUS, the underlying Windows message:

While processing this message, do not make any function calls that display or activate a window. This causes the thread to yield control and can cause the application to stop responding to messages. For more information, see Message Deadlocks.

Use the Leave event instead.

Hans Passant