unit TRM_ImageLabel;
interface
uses
System.SysUtils, System.Classes,
Vcl.Controls,
Vcl.ExtCtrls,
Vcl.StdCtrls,
Vcl.Imaging.GIFConsts,
Vcl.Imaging.GIFImg,
Vcl.Imaging.JConsts,
Vcl.Imaging.jpeg,
Vcl.Imaging.pngimage,
Vcl.Imaging.pnglang;
type
TLabelPosition = (lpTop, lpBottom, lpLeft, lpRight);
TTRM_ImageLabel =
class(TCustomPanel)
private
FSubImageComponent: TImage;
FSubLabelComponent: TLabel;
FLabelPosition: TLabelPosition;
procedure SetLabelPosition(
const Value: TLabelPosition);
protected
procedure Resize;
override;
public
constructor Create(AOwner: TComponent);
override;
published
property SubImageComponent: TImage
read FSubImageComponent;
property SubLabelComponent: TLabel
read FSubLabelComponent;
property Align;
property Anchors;
property OnClick;
property OnDblClick;
property OnMouseEnter;
property OnMouseLeave;
property LabelPosition: TLabelPosition
read FLabelPosition
write SetLabelPosition;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
TRM', [TTRM_ImageLabel]);
end;
{ TTRM_ImageLabel }
constructor TTRM_ImageLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
(* Für meine eigenen Bedürfnisse *)
Self.Width := 64;
Self.Height := 97;
FSubImageComponent := TImage.Create(Self);
FSubImageComponent.Parent := Self;
FSubImageComponent.Align := alClient;
FSubLabelComponent := TLabel.Create(Self);
FSubLabelComponent.Parent := Self;
FSubLabelComponent.Height := 25;
FSubLabelComponent.AlignWithMargins := False;
FSubLabelComponent.Margins.Left := 0;
FSubLabelComponent.Margins.Right := 0;
FSubLabelComponent.Margins.Top := 8;
FSubLabelComponent.Margins.Bottom := 0;
FSubLabelComponent.Caption := '
TEST';
SubLabelComponent.Font.Size := 14;
FLabelPosition := lpBottom;
Resize;
end;
procedure TTRM_ImageLabel.Resize;
begin
inherited;
case FLabelPosition
of
lpTop:
begin
FSubLabelComponent.Align := alTop;
FSubLabelComponent.Alignment := taCenter;
end;
lpBottom:
begin
FSubLabelComponent.Align := alBottom;
FSubLabelComponent.Alignment := taCenter;
end;
lpLeft:
begin
FSubLabelComponent.Align := alLeft;
FSubLabelComponent.Alignment := taCenter;
end;
lpRight:
begin
FSubLabelComponent.Align := alRight;
FSubLabelComponent.Alignment := taCenter;
end;
end;
end;
procedure TTRM_ImageLabel.SetLabelPosition(
const Value: TLabelPosition);
begin
if FLabelPosition <> Value
then
begin
FLabelPosition := Value;
Resize;
end;
end;
end.