PC Review


Reply
Thread Tools Rate Thread

Custom Control questions

 
 
Nathan Laff
Guest
Posts: n/a
 
      4th May 2007
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.

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.

Thanks

 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      4th May 2007
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
 
Reply With Quote
 
Nathan Laff
Guest
Posts: n/a
 
      4th May 2007
Thanks. I'll try that.

I'm not inheriting from a Label because it's a transparent control overtop
of an image.
i'm drawing a focus rectangle around it, because it's like a clickable
dropdown menu. i don't want a button there

"Peter Duniho" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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


 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      4th May 2007
On Fri, 04 May 2007 10:54:04 -0700, Peter Duniho
<(E-Mail Removed)> wrote:

> [...]
>> 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.


I'm sorry...I'm a little tired today, and that answer was wrong in at
least two ways.

First, you won't get key events unless you have focus. The correct place
to handle the event is in the parent form, not the control itself.
Second, you can't get "Alt" information in the KeyPress event. What you
really want is the KeyDown event.

Other than those rather significant errors, I think the answer is fine.

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Control Installation questions Elmo Watson Microsoft ASP .NET 1 18th Aug 2007 08:44 PM
ASP.NET Custom Control Questions [Newbie] DaBrain Microsoft C# .NET 1 27th Oct 2006 04:37 PM
Custom Web Control - viewstate and event wiring questions =?Utf-8?B?amVzc2UgamFtZXMgMjAyMA==?= Microsoft ASP .NET 0 18th Aug 2006 04:39 PM
[ CONTROLARRAY Erik Porter Custom control] Few questions about it... bis Microsoft Dot NET 0 12th Sep 2005 08:12 PM
Custom StatusBar control questions lj Microsoft Access Form Coding 0 24th Feb 2004 04:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 AM.