If you want to intercept the TAB key behavior, you should catch the CM_DIALOGKEY
message. In this example, if you set the YouWantToInterceptTab
boolean value to True, the TAB
key will be eaten:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
private
YouWantToInterceptTab: Boolean;
procedure CMDialogKey(var AMessage: TCMDialogKey); message CM_DIALOGKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CMDialogKey(var AMessage: TCMDialogKey);
begin
if AMessage.CharCode = VK_TAB then
begin
ShowMessage('TAB key has been pressed in ' + ActiveControl.Name);
if YouWantToInterceptTab then
begin
ShowMessage('TAB key will be eaten');
AMessage.Result := 1;
end
else
inherited;
end
else
inherited;
end;
end.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…