Delphi 拦截Tab按键消息


本文整理自网络,侵删。

 
如果要拦截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 : tstringlist的find,indexof和sort

Delphi 判断端口(port)是否被占用

Delphi 万年历 程序源码下部分(包括:农历计算、24节气、星期计算、属相)

Delphi 运行js

Delphi 取得 ios 辅助使用里的字型大小

Delphi 流分割与合并文件的函数

Delphi判断一个字符是否为汉字的最佳方法

Delphi中unicode转中文

Delphi 用idhttp打开网页或下载文件时如何显示进度

Delphi 搜索某个字的位置 [带重复]

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...