By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Proper LostFocus behavior

P: n/a
All -

I am in the process of developing a custom control that mimics the Office
2003 "Inbox" as closely as possible. After a great deal of frustrating work
trying to do a heavily custom-drawn ListView (which is how I believe MS is
doing it) and getting nowhere, I said "screw it" and built the thing from
scratch. I have a UserControl with a few contained controls, a header
control I'm drawing entirely by hand, and a Panel in which I'm doing all my
item drawing (also entirely by hand.) The hierarchy looks like this:

- Label (actually a 3rd party label control so I can get the gradient)
- Panel
--- Custom header control (docked to the top of the parent panel)
--- Vertical scrollbar (docked to the right of the parent panel)
--- "client area" panel (docked as "Fill" of the parent panel)

I have coded up "Enter" and "Leave" events for the "client area" panel, so
that I can get the appropriate colors for selected items, and the focus
rectangle when necessary. However, once I put my control on a form, these
events aren't firing when the containing form loses focus. I have a
TreeView control on the form - purely to test my focus-related code - and
the TreeView does fire a LostFocus event when the form loses focus. The
actual UserControl fires a LostFocus event when I click into my panel (which
kinda makes sense, but not really), but not when the form is deactivated.
Hooking a LostFocus to my panel does nothing at all.

I've tried to switch from a UserControl base to a ContainerControl base,
thinking that the UserControl was somehow "taking over" the focus events
from its contained controls. But that didn't solve anything. Trying the
"ChangeUICues" event didn't get me anywhere either.

I can't believe that the solution is to pass a reference to the containing
form into the control and catch the "Deactivate" event, but that's what I'm
left with. I am obviously missing something fundamental about all this.
Can someone please point me in the right direction?


- Scott
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.