• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

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.

0
Marius0188
Asked:
Marius0188
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
ZhaawZSoftware 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now