unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ExtCtrls, StdCtrls, ImgList;
type
TMyPanel=Class(TCustomPanel)
Procedure Paint;
override;
private
FImageList:TImageList;
FImageIndex: Integer;
procedure SetImageIndex(
const Value: Integer);
procedure SetImageList(
const Value: TImageList);
published
Property ImageList:TImageList
read FImageList
Write SetImageList;
Property ImageIndex:Integer
Read FImageIndex
Write SetImageIndex;
End;
TForm2 =
class(TForm)
ImageList1: TImageList;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TMyPanel }
procedure TMyPanel.Paint;
const
C_LOFS=10;
var
ico:TIcon;
Toffs:Integer;
begin
// inherited; nicht aufrufen
Canvas.Brush.Color := clSilver;
Canvas.FillRect(ClientRect);
Toffs := C_LOFS;
if Assigned(FImageList)
and (FImageList.Count>ImageIndex )
then
try
ico:=TIcon.Create;
FImageList.GetIcon(ImageIndex,ico);
Canvas.Draw(C_LOFS,(Height - FImageList.Height)
div 2,ico);
Toffs := Toffs + FImageList.Width + 5;
finally
ico.Free;
end;
Canvas.TextOut(Toffs,(Height - Canvas.TextHeight('
X'))
div 2, Caption);
end;
procedure TMyPanel.SetImageIndex(
const Value: Integer);
begin
FImageIndex := Value;
invalidate;
end;
procedure TMyPanel.SetImageList(
const Value: TImageList);
begin
FImageList := Value;
invalidate;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
With TMyPanel.Create(self)
do
begin
Parent := Self;
Caption := '
Mein Testpanel';
Width := 200;
Height := 50;
Left := 50;
Top := 50;
Imagelist := IMagelist1;
ImageIndex := 0;
end;
end;
end.