Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Label OnClick event

0 views
Skip to first unread message

Dorothy

unread,
Oct 5, 2005, 9:23:32 AM10/5/05
to
Hi,

I have a Label with an OnClick event that executes a procedure.
When I click on the label using mouse, the OnClick event gets fired, but
when I use the keyboard by pressing the Alt + Hotkey (given to one letter in
the label), then event is not fired.

Can u please help me get the OnClick event fired using the keyboard??

Thanks,
Dorothy


Sven Pran

unread,
Oct 5, 2005, 11:00:49 AM10/5/05
to

"Dorothy" <dorothy...@hotmail.com> wrote in message
news:4343d22d$1...@newsgroups.borland.com...

I guess the following description on TLabel explains it all:

TLabel is not a descendant of TWinControl, so it does not have its own
window and can’t receive direct input from the keyboard. To add an object
to a form that can respond to keyboard input (other than setting focus to
another object when an accelerator key is typed) in addition to displaying
text, use TStaticText.

Regards Sven


Peter Below (TeamB)

unread,
Oct 5, 2005, 2:14:32 PM10/5/05
to

That is not too difficult. You need to make a descendent of TLabel and handle
the CM_DIALOGCHAR message in it. The technique is shown here using an
interposer class:

type
TLabel = class(StdCtrls.TLabel)
protected
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
end;
TForm1 = class(TForm)
StatusBar: TStatusBar;
.....


procedure TLabel.CMDialogChar(var Message: TCMDialogChar);
begin
if (FocusControl = nil) and Enabled and ShowAccelChar and
IsAccel(Message.CharCode, Caption)
then
Click
else
inherited;
end;

If a Focuscontrol is assigned the label will revert to the standard behaviour,
otherwise using the shortcut will "Click" the label.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


0 new messages