delphi

Transfer mousedown event on a control to its parent control


There is a label on a panel. Is it possible to transfer mousedown event to parent control, when there is mousedown event on label, it can trigger mousedown event of its parent panel?


Solution

  • Try this:

    type
      TMyControl = class(TControl);
    
    procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton; Shift:
        TShiftState; X, Y: Integer);
    begin
      TMyControl(Label1.Parent).MouseDown(Button, Shift, X, Y);
    end;
    

    The TMyControl declaration is there to get access to TControl's protected-visibility MouseDown method.