Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#15

AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt

  Alt 14. Mai 2024, 12:16
Ich habs mal versucht nachzustellen wobei ich gleich auf TPanel umgestiegen bin.
Zur laufzeit benötige ich nicht mehr als:
Delphi-Quellcode:
unit EinUnitName;

interface

uses
  System.SysUtils,
  System.Classes,
  Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TLabeledImage = class(TCustomPanel)
    strict private
      FImage: TImage;
      FLabel: TLabel;
    public
      constructor Create(AOwner: TComponent);
      destructor Destroy; override;
    published
      property Img: TImage read FImage write FImage;
      property Lbl: TLabel read FLabel write FLabel;
  end;

implementation

{ TLabeledImage }

constructor TLabeledImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Self.Parent := TWinControl(AOwner);
  FLabel := TLabel.Create(Self);
  try
    FLabel.Parent := Self;
    FLabel.Align := alBottom;
    FLabel.Alignment := taCenter;
    FLabel.Caption := '';
    FLabel.Visible := True;
  finally
  end;
  FImage := TImage.Create(Self);
  try
    FImage.Parent := Self;
    FImage.Align := alClient;
    FImage.Visible := True;
  finally
  end;
  Self.Width := 150;
  Self.Height := 150;
end;

destructor TLabeledImage.Destroy;
begin
  FImage.Free;
  FLabel.Free;
  inherited Destroy;
end;

end.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat