On Fri, 04 May 2007 08:52:31 -0700, Nathan Laff <(E-Mail Removed)>
wrote:
> I have a custom Control that is a label, however I inherit from
> Control...
>
> 1) I override onClick and do a DrawFocusRectangle, that works great. How
> do I clear the focus rectangle once something else on the parent is
> clicked? I tried to override OnLostFocus and invalidate but that doesn't
> seem to do it.
Are you actually getting focus when you get the OnClick event? And are
you calling the base methods in your overrides?
It seems to me that it makes more sense to override the OnGotFocus event
handler, just as you override the OnLostFocus event handler. Then you can
track when focus changes and redraw accordingly. If I recall, the base
Control class already handles basic focus-changing issues, so all you
really need is notification when focus changes.
Overriding OnClick, you may be drawing your focus rectangle without
actually having focus. Also, using the OnClick method to deal with focus
changes leaves you open to missing focus changes for other reasons (tab
key, for example).
I find it a little odd that you want your label to even have the focus;
that's unusual behavior for a label. So that's something to think about
too.
> 2) the control, like i said is a label, how do i override the hotkey
> behavior. I.e, if my text is &Help, when I do Alt-H on the parent, i
> want to respond to the hotkey, but i can't quite figure it out.
Override the OnKeyPress event handler and if you get Alt-H, set the focus
to the next control in the tab order.
That said, since you're basically doing a custom label, you might want to
consider inheriting from the Label control and just overriding the
behavior you want to change (like redrawing and allowing focus on a
label), and you could automatically get things like the Text and
UseMnemonic properties already in a Label control.
Pete