Delphi VCL make element "transparent" to clicks
Asked Answered
L

1

2

Is it possible to make VCL element transparent to clicks like disabling hit test in FMX?

Libratory answered 5/8, 2014 at 11:55 Comment(4)
If the control is a WinControl writing a WM_NCHITTEST handler returning HTTRANSPARENT might do the trick. But I don't know if this works only on top level windows or all controls with a handle.Twobyfour
@CodesInChaos, it works also for child windows. That's how e.g. TCustomTransparentControl allows clicks through when its InterceptMouse property is set to False.Credit
Disable the control if you don't mind the look, or if it doesn't change (e.g. panel).Beaman
For non-wincontrols, you can return HTNOWHERE to CM_HITTEST.Beaman
B
2

Put two Memos on the Form, but Memo2 partially behind Memo1 to test. Then add this code:

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.
Biscuit answered 5/8, 2014 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.