2

Как в делфи наваять нечто подобное в виде компонента, для динамического создания в дальнейшем? скриншот

На панели image и 2 лейбла, находятся на фиксированных положениях относительно панели. 5 обязательных свойств: Component.Top, Component.Left, Component.Picture, Component.Caption, Component.Caption2. Добро это, создаваясь динамически, будет отображать нечто вроде карточек, ессно, реагировать на OnClick и иметь PopupMenu.

1
  • 2
    создайте TFrame с необходимыми компонентами и обработчиками и штампуйте их сколько нужно. 5 фев 2014 в 21:44

1 ответ 1

2

Накатал компонент по быстрому может вам подойдет.
Вроде работает без проблем.
Единственно картинки придется загружать квадратные типа 100Х100 и подобные.

//** nitroglicirin  production***
unit SpecialPanel;
interface
uses
  SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Graphics;

type
  // Унаследуем от TPanel
  TSpecialPanel = class(TPanel)
  private
    FImage: TImage;
    F_ALabel: TLabel;
    F_BLabel: TLabel;
    F_AFont: TFont;
    F_BFont: TFont;
    F_ACaption: TCaption;
    F_BCaption: TCaption;
    procedure SetFontA(const Value: TFont);
    procedure SetFontB(const Value: TFont);
    function GetACaption: TCaption;
    procedure SetACaption(F_AC: TCaption);
    function GetBCaption: TCaption;
    procedure SetBCaption(F_BC: TCaption);
    Function GetPicture:TPicture;
    Procedure SetPicture(const Value:TPicture);
  protected
    procedure Resize; override;
    procedure Paint; override;
    property Image: TImage read FImage;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property AFont:TFont read F_AFont write SetFontA;
    property BFont:TFont read F_BFont write SetFontB;
    property ACaption: TCaption read GetACaption write SetACaption;
    property BCaption: TCaption read GetBCaption write SetBCaption;
    property Picture:TPicture read GetPicture write SetPicture;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TSpecialPanel]);
end;

{ TSpecialPanel }

constructor TSpecialPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  F_AFont:=TFont.Create;
  F_BFont:=TFont.Create;
  height:=80;
  width:=200;
  Caption:='';
  F_ACaption:='ALabel';
  F_BCaption:='BLabel';
  FImage := TImage.Create(Self);
  with FImage do
  begin
    Parent := Self;
    Align := alNone;
    AutoSize := False;
    Stretch := True;
  end;
  F_ALabel := TLabel.Create(Self);
  with F_ALabel do
  begin
    Parent := Self;
    Visible := True;
    Transparent:=True;
  end;
  F_BLabel := TLabel.Create(Self);
  with F_BLabel do
  begin
    Parent := Self;
    Visible := True;
    Transparent:=True;
  end;
  FImage.Top:=10;
  FImage.Left:=10;
  FImage.Height:=Height-20;
  FImage.Width:=Height-20;
  F_ALabel.Left:=20+FImage.Width;
  F_BLabel.Left:=20+FImage.Width;
  F_ALabel.Top:=(FImage.Height div 3) + FImage.Top - (F_ALabel.Height div 2);
  F_BLabel.Top:= ((FImage.Height div 3)*2) + FImage.Top - (F_BLabel.Height div 2);
  F_ALabel.Font:=F_AFont;
  F_BLabel.Font:=F_BFont;
  F_ALabel.Caption:=F_ACaption;
  F_BLabel.Caption:=F_BCaption;
end;

destructor TSpecialPanel.Destroy;
begin
  F_AFont.Free;
  F_BFont.Free;
  FImage.Free;
  inherited Destroy;
end;

function TSpecialPanel.GetACaption: TCaption;
begin
  Result := F_ACaption;
end;

function TSpecialPanel.GetBCaption: TCaption;
begin
  Result := F_BCaption;
end;

function TSpecialPanel.GetPicture: TPicture;
begin
  Result:=FImage.Picture;
end;

procedure TSpecialPanel.Paint;
begin
  FImage.Top:=10;
  FImage.Left:=10;
  FImage.Height:=Height-20;
  FImage.Width:=Height-20;
  F_ALabel.Left:=20+FImage.Width;
  F_BLabel.Left:=20+FImage.Width;
  F_ALabel.Top:=(FImage.Height div 3) + FImage.Top - (F_ALabel.Height div 2);
  F_BLabel.Top:= ((FImage.Height div 3)*2) + FImage.Top - (F_BLabel.Height div 2);
  F_ALabel.Font:=F_AFont;
  F_BLabel.Font:=F_BFont;
  F_ALabel.Caption:=F_ACaption;
  F_BLabel.Caption:=F_BCaption;
end;

procedure TSpecialPanel.Resize;
begin
  inherited;
  FImage.Top:=10;
  FImage.Left:=10;
  FImage.Height:=Height-20;
  FImage.Width:=Height-20;
  F_ALabel.Left:=20+FImage.Width;
  F_BLabel.Left:=20+FImage.Width;
  F_ALabel.Top:=(FImage.Height div 3) + FImage.Top - (F_ALabel.Height div 2);
  F_BLabel.Top:= ((FImage.Height div 3)*2) + FImage.Top - (F_BLabel.Height div 2);
  F_ALabel.Font:=F_AFont;
  F_BLabel.Font:=F_BFont;
  F_ALabel.Caption:=F_ACaption;
  F_BLabel.Caption:=F_BCaption;
end;

procedure TSpecialPanel.SetACaption(F_AC: TCaption);
begin
  F_ACaption := F_AC;
  Invalidate;
end;

procedure TSpecialPanel.SetBCaption(F_BC: TCaption);
begin
  F_BCaption := F_BC;
  Invalidate;
end;

procedure TSpecialPanel.SetFontA(const Value: TFont);
begin
  F_AFont.Assign(Value);
  Invalidate;
end;

procedure TSpecialPanel.SetFontB(const Value: TFont);
begin
  F_BFont.Assign(Value);
  Invalidate;
end;

procedure TSpecialPanel.SetPicture(const Value: TPicture);
begin
  FImage.Picture:=Value;
  Invalidate;
end;

end.

Как установить думаю сами разберётесь.

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.