Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#5

AW: Transparente Clicks

  Alt 7. Feb 2020, 10:52
Also letztens hatte ich eine ähnliche Situation und da hat es geholfen im WndProc der Komponente für die WM_NCHITTEST Message HTTRANSPARENT zurückzugeben.

Ich hab das allerdings grad für ein Label getestet und da kommt scheinbar diese Message überhaupt nicht an.

Wenn du alle Labels in TStaticText änderst/ändern kannst funktioniert es aber:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TStaticText = class(Vcl.StdCtrls.TStaticText)
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

  TForm1 = class(TForm)
    StaticText1: TStaticText;
    Image1: TImage;
    procedure StaticText1Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Image1Click(Sender: TObject);
begin
  ShowMessage('Image');
end;

procedure TForm1.StaticText1Click(Sender: TObject);
begin
  ShowMessage('Label'); // Wird so nie aufgerufen, stattdessen wird der Klick an das Image weitergeleitet
end;

{ TStaticText }

procedure TStaticText.WndProc(var Message: TMessage);
begin
  if Message.Msg = WM_NCHITTEST then
    Message.Result := HTTRANSPARENT
  else
    inherited;
end;

end.
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."

Geändert von Neutral General ( 7. Feb 2020 um 10:57 Uhr)
  Mit Zitat antworten Zitat