如果要拦截TAB键行为,应该捕获 CM_DIALOGKEY 消息。在这里示例中,如果将 YouWantToInterceptTab 布尔值设置为 true,则将会吃掉 TAB 键:
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.
本文介绍了一种在Delphi中通过捕获CM_DIALOGKEY消息来拦截窗口内TAB键的方法。通过设置布尔变量YouWantToInterceptTab,可以决定是否拦截TAB键,并阻止其默认行为。
2081

被折叠的 条评论
为什么被折叠?



