Delphi VCL使点击“透明”

时间:2014-08-05 11:55:16

标签: delphi delphi-xe6

是否可以使VCL元素对点击更加透明,例如在FMX中禁用点击测试?

1 个答案:

答案 0 :(得分:1)

在表单上放两个备忘录,但Memo2部分在Memo1后面进行测试。然后添加以下代码:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Memo2Enter(Sender: TObject);
    procedure Memo2Exit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    OriginalProc:TWndMethod;
    procedure MyWindowProc(var Msg: TMessage);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  OriginalProc:=Memo1.WindowProc;
  Memo1.WindowProc:=MyWindowProc;
end;

procedure TForm1.MyWindowProc(var Msg: TMessage);
begin
  OriginalProc(Msg);
  if Msg.Msg = WM_NCHITTEST then Msg.Result:=HTTRANSPARENT;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Memo1.WindowProc:=OriginalProc;
end;

procedure TForm1.Memo2Enter(Sender: TObject);
begin
  Memo2.Color:=clRed;
end;

procedure TForm1.Memo2Exit(Sender: TObject);
begin
  Memo2.Color:=clWhite;
end;

end.