Board index » cppbuilder » How come No OnKeyPress for TPanel or TTabControl?

How come No OnKeyPress for TPanel or TTabControl?


2004-08-04 10:52:06 AM
cppbuilder36
I want to have different hot key mappings on different areas of a form. One approach
to accomplishing this seems the straightforward one of intercepting OnKeyDown or
OnKeyPress in each area. For instance, TTreeView has OnKeyDown, OnKeyUp, and OnKeyPress.
But neither TPanel or TTabContorl have TPanel. Yet one area of a form that I want to
assign a unique set of key mappings to is bounded by a TPanel which has a TTabControl
in it. Either one of those controls makes a logical place to intercept key hits to
make hot key mappings for their area of the form.
So why don't TPanel and TTablControl have any key hit events? Also, how else to solve
this problem of processing hot key selections differently on different areas of the
form? I do not want to do it on a per control basis. There are too many differnet
kinds of controls on the form to do it that way.
Suggestions?
 
 

Re:How come No OnKeyPress for TPanel or TTabControl?

Randall Parker < XXXX@XXXXX.COM >wrote:
Quote
[...] So why don't TPanel and TTablControl have any key hit
events?
Not to be flipant but that's the way that they made it.
See my reply to your other post for a solution to your problem.
~ JD
 

Re:How come No OnKeyPress for TPanel or TTabControl?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:41104f3a$ XXXX@XXXXX.COM ...
Quote
how else to solve this problem of processing hot key
selections differently on different areas of the form?
Why not simply have OnKey... events at the form level (set the form's
KeyPreview property to true) and then use the form's ActiveControl property
to know which component will receive the keystrokes?
Gambit
 

{smallsort}

Re:How come No OnKeyPress for TPanel or TTabControl?

Remy Lebeau (TeamB) wrote:
Quote
Why not simply have OnKey... events at the form level (set the form's
KeyPreview property to true) and then use the form's ActiveControl property
to know which component will receive the keystrokes?
Remy,
I am currently using OnKeyDown events at the form level. One of the approaches I'm
considering is to figure out in OnKeyDown of the form what control has focus and what
chain of parents it has that would let me know where it is in the form. I see JD has
recommeded using the Tag field that is a member of all controls inheriting from
TComponent.
Maybe I could go up the hierarchy of parents until I found one that has a tag that is
in some sort of number range. I could make my main areas each have a parent with a
distinct tag number that is the range of 100 to 200. Then look for a tag that is in
that range and then feed its value into a case statement to know how to interpret the
key hit. 101 could be for the first area, 102 for the second, and so on. Or 100, 200,
and so on. I'd rather not have to tag every single control appropriately since there
are a lot of controls and I want to avoid the maintenance headache.
TForm's ActiveControl is a TWinControl. Well, TPanel does not inherit from
TWinControl (and hence does not get the OnKeyXXX events). So that is why a group of
controls that are in a TPanel can not easily have all their key input specially handled.
 

Re:How come No OnKeyPress for TPanel or TTabControl?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:4110932e$ XXXX@XXXXX.COM ...
Quote
TPanel does not inherit from TWinControl
Yes, it does.
Quote
and hence does not get the OnKeyXXX events.
All visual components have OnKey... events inherited from TControl. Not all
components expose the events as public or published, but the events are
still present nontheless and can be accessed if needed.
Gambit
 

Re:How come No OnKeyPress for TPanel or TTabControl?

Remy,
I stand corrected on the inheritance. So what is entailed in getting access to the
OnKeyDown event of a TPanel?
Remy Lebeau (TeamB) wrote:
Quote
All visual components have OnKey... events inherited from TControl. Not all
components expose the events as public or published, but the events are
still present nontheless and can be accessed if needed.
 

Re:How come No OnKeyPress for TPanel or TTabControl?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:41111d5f$ XXXX@XXXXX.COM ...
Quote
I stand corrected on the inheritance. So what is entailed
in getting access to the OnKeyDown event of a TPanel?
Derive a new class that promotes the events from protected to
public/published.
Gambit
 

Re:How come No OnKeyPress for TPanel or TTabControl?

Remy Lebeau (TeamB) wrote:
Quote
"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:41111d5f$ XXXX@XXXXX.COM ...
>I stand corrected on the inheritance. So what is entailed
>in getting access to the OnKeyDown event of a TPanel?
Derive a new class that promotes the events from protected to
public/published.
Why do you say public/published rather than just published?
Should I just put the function prototype in the __published section?
 

Re:How come No OnKeyPress for TPanel or TTabControl?

"Randall Parker" < XXXX@XXXXX.COM >wrote in
message news:41112fa9$ XXXX@XXXXX.COM ...
Quote
Why do you say public/published rather than just published?
Because whether you choose public or published is your own choice based on
how you are actually going to use the class. Published is exactly the same
as public except for the RTTI support that is included.
Quote
Should I just put the function prototype in the __published section?
You don't redeclare anything. All you need to do is promote the existing
events. You do know how to promote properties, don't you? You simply
declare the names only, no data types, no read/write specifiers. For
example:
class TMyPanel : public TPanel
{
__published:
__property OnKeyDown;
__property OnKeyPress;
__property OnKeyUp;
};
Ganbit