unit ImageListBox;
interface
uses
Windows, Classes, Graphics, Controls, StdCtrls, Imglist;
type
TImageListBox =
class(TListbox)
private
FImageList: TImageList;
procedure SetImageFromList(
const Value: TImageList);
public
constructor Create(AOwner: TComponent);
override;
procedure DrawItem(
Index: Integer; Rect: TRect; State: TOwnerDrawState);
override;
published
property ImageList: TImageList
read FImageList
write SetImageFromList;
end;
procedure Register;
implementation
// Register -----------------------------------------------------------------
procedure Register;
begin
RegisterComponents('
Samples', [TImageListBox]);
end;
// --------------------------------------------------------------------------
constructor TImageListBox.Create(AOwner: TComponent);
begin
inherited;
Style := lbOwnerDrawVariable;
ControlStyle := ControlStyle + [csAcceptsControls];
end;
procedure TImageListBox.DrawItem(
Index: Integer; Rect: TRect;
State: TOwnerDrawState);
var
Bmp: TBitmap;
begin
if FImageList <>
nil then
begin
Bmp := TBitMap.Create;
FImageList.GetBitmap(
Index, Bmp);
ItemHeight := Bmp.Height;
with Canvas
do
begin
FillRect(Rect);
if FImageList.DrawingStyle = dsTransparent
then
begin
Canvas.BrushCopy(
Bounds(Rect.Left, Rect.Top, Bmp.Width, Bmp.Height),Bmp,
Bounds(0, 0, Bmp.Width, Bmp.Height), Bmp.TransparentColor);
end else
Draw(Rect.Left , Rect.Top, Bmp);
TextOut(
Rect.Left + Bmp.Width + 5,
(Rect.Top + (Rect.Bottom-Rect.Top)
div 2) - (TextHeight('
X')
div 2),
Items.Strings[
Index]);
end;
Bmp.Free;
end;
end;
procedure TImageListBox.SetImageFromList(
const Value: TImageList);
begin
FImageList := Value;
Self.Repaint;
end;
end.