Shortcut keyboard keys for Label component

Dear Experts,

I am using TLabel components as buttons on an application that uses allot of graphics as part of the interface.
This interface does limit me because I can not for example set a label's caption:
"&Ok" and the underscore "O" will serve as a shortcut key.

1) How can I implement this functionality with using TLabel components.
    Please note that I would prefer to get a way of working WITH the TLabel components
    as I my entire application is completed and to change all the buttons will be allot of work.

2) Maybe if there are freeware components that can assist with this task I would be glad to hear of them.

Marius0188Asked:
Who is Participating?
 
ZhaawZConnect With a Mentor Software DeveloperCommented:
You should add 'inherited' to CMDialogChar procedure (before or after Click() - it depends on where you need it) if you want to leave also default processing of that message:

procedure TLabel.CMDialogChar(var Message: TCMDialogChar);
begin
inherited;
Click;
end;
0
 
BlackTigerXCommented:
you want to know of freeware components to do the job, but you don't want to replace your labels with buttons?
0
 
DragonSlayerCommented:
The Underscore *will* serve as a shortcut key, if you set the FocusControl property to the control you want it to activate.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Marius0188Author Commented:
I need the TLables to function as buttons in regards to the ALT+KEY shortcut.
Need to be exactly the same.

Whether it's got focus or not when you press the ALT combination of any of the Lables it must be clicked then.
0
 
DragonSlayerCommented:
In that case, you should use buttons. Download and install GExperts http://gexperts.org/

Once installed, there is an IDE add-on to Replace Components, so you can essentially replace all your Labels with Buttons.
0
 
ZhaawZSoftware DeveloperCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  // added manually
  TLabel = class(StdCtrls.TLabel)
    protected procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  end;
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure Label1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// added manually
procedure TLabel.CMDialogChar(var Message: TCMDialogChar);
begin
Click;
end;

// default onClick event
procedure TForm1.Label1Click(Sender: TObject);
begin
ShowMessage('blah');
end;

end.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.