TLable不是从WinControl继承下来的,没有handle,不吃焦点,也没KeyDown事件.
用别的控件吧
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyStaticText = class(TStaticText)
public
property OnKeyDown;
end;
TForm1 = class(TForm)
procedure FStaticText1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
FStaticText1: TMyStaticText;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FStaticText1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
ShowMessage('KeyDown');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FStaticText1 := TMyStaticText.Create(Self);
FStaticText1.Caption := 'fffffffff';
FStaticText1.Parent := Self;
FStaticText1.TabStop := True;
FStaticText1.Top := 100;
FStaticText1.Left := 100;
FStaticText1.OnKeyDown := FStaticText1KeyDown;
end;
end.