本文介绍了截取TAB键并抑制它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我需要截取TEdit上的TAB键盘敲击并以编程方式抑制它们。
在某些情况下,我不希望将焦点更改为下一个控件。

I need to intercept the TAB keyboard stroke on TEdits and suppress them programmatically.In certain cases I don't want the focus to change to the next control.

我尝试在TEdit级别和TForm上处理KeyPress,KeyDown KeyPreview = true。
我已经看过以下意见:

I tried to handle KeyPress, KeyDown both on TEdit level and on TForm with KeyPreview=true.I've peeked advices from:



  • Intercept TAB key in RichEdit
  • How do I make the TAB key close a TComboBox without losing the current position?

但它没有起作用。
事件被触发,让我们说,输入键,但不是TAB键。

But it didn't work.The events are fired for, let's say, the Enter key BUT not for the TAB key.

我使用的是Delphi 7.
谢谢为您的帮助。

I'm using Delphi 7.Thanks for your help.

推荐答案

如果要拦截TAB键行为,应该抓住 CM_DIALOGKEY 讯息。在这个例子中,如果您将 YouWantToInterceptTab 布尔值设置为True,那么 TAB 键将被删除:

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.

这篇关于截取TAB键并抑制它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:15