A: This one uses four of the bitmaps that come with windows.
unit Bm_outln;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, Grids, Outline, Dialogs;
type
TForm1 = class(TForm)
Outline1: TOutline;
Button1: TButton;
procedure Outline1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
bitmaps : array[1..4] of TBitmap;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Outline1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
VisibleCount,
ActualIndex: Integer;
BitMap : TBitMap;
Offset: Longint;
begin
{draw on the control canvas, not on the form }
{ Find Item }
with Control as TOutLine do begin
VisibleCount := 0;
for ActualIndex := 1 to ItemCount do begin
if Items[ActualIndex].IsVisible then
inc(VisibleCount);
if Index = VisibleCount-1 then break;
end; { for }
Bitmap := TBitmap(Items[ActualIndex].data);
with Canvas do begin
if Bitmap <> nil then begin
FillRect(Rect);
BrushCopy(Bounds(Rect.Left
+ 2 + (Items[ActualIndex].level-1) * 16,
Rect.Top, 16, 16), Bitmap,
Bounds(0, 0, Bitmap.Width, Bitmap.Height), clBackGround);
end;
if odSelected in State then begin
Font.Color := clHighLightText;
Brush.Color := clhighLight;
end; { if }
TextOut(Rect.Left + 5 + (Items[ActualIndex].level)
* 16,
Rect.Top, Items[ActualIndex].Text);
Font.Color := clWindowText;
Brush.Color := clWindow;
end; { with }
end; { with }
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with OutLine1 do begin
AddObject(0, 'Level 1', Bitmaps[1]);
AddChildObject(1, 'Level 2', Bitmaps[2]);
AddChildObject(2, 'Level 3', Bitmaps[3]);
AddChildObject(3, 'Level 4', Bitmaps[4]);
AddObject(0, 'Level 1(a)', Bitmaps[1]);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bitmaps[1] := TBitmap.create;
bitmaps[2] := TBitmap.create;
bitmaps[3] := TBitmap.create;
bitmaps[4] := TBitmap.create;
bitmaps[1].LoadFromFile('c:\windows\honey.bmp');
bitmaps[2].LoadFromFile('c:\windows\cars.bmp');
bitmaps[3].LoadFromFile('c:\windows\tiles.bmp');
bitmaps[4].LoadFromFile('c:\windows\waves.bmp');
end;
end.
There was a compuserve posting that gave an alternative coding because the above code didn't work for them. (It works fine for me. <G>) I am including it here for completeness.
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, DBTables, DB, StdCtrls, Grids, Outline;
type
TForm1 = class(TForm)
Outline1: TOutline;
Button1: TButton;
procedure Outline1DrawItem(Control: TWinControl;
Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
bitmaps: array[1..5] of tbitmap;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Outline1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
BitMap: TBitMap; {for
the item's bitmap }
OffSet, VisibleCount, ActualIndex: Integer;
begin
{draw on the control canvas, not on the form }
{ Find Item }
VisibleCount := 0;
Offset:= 25;
with OutLine1 do begin
for ActualIndex := 1 to ItemCount do begin
if Items[ActualIndex].IsVisible then
inc(VisibleCount);
if Index = VisibleCount-1 then break;
end; { for }
if ActualIndex = ItemCount then exit;
{ rectangle }
Bitmap := bitmaps[ActualIndex];
with Canvas do
if Bitmap <> nil then begin
BrushCopy(Bounds(Rect.Left
+ 2+ Items[ActualIndex].level * 10,
Rect.Top, Bitmap.Width,
Bitmap.Height), Bitmap,
Bounds(0, 0, Bitmap.Width, bitmap.Height), clPurple);
{ four pixels between bitmap and text }
Canvas.TextOut(Rect.Left
+ Offset + Items[ActualIndex].level * 10, Rect.Top, Items[ActualIndex].Text);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with OutLine1 do begin
AddObject(0, 'Level 1', Bitmaps[1]);
AddChildObject(1, 'Level 2', Bitmaps[2]);
AddChildObject(2, 'Level 3', Bitmaps[3]);
AddChildObject(3, 'Level 4', Bitmaps[4]);
AddChildObject(4, 'Level 5', Bitmaps[5]);
AddChildObject(0, 'Level 1(a)', Bitmaps[1]);
FullExpand;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
chdir(extractFilePath(Paramstr(0)));
bitmaps[1] := tbitmap.create;
bitmaps[2] := tbitmap.create;
bitmaps[3] := tbitmap.create;
bitmaps[4] := tbitmap.create;
bitmaps[5] := tbitmap.create;
bitmaps[1].loadfromfile('bitmap1.bmp');
bitmaps[2].loadfromfile('bitmap2.bmp');
bitmaps[3].loadfromfile('bitmap3.bmp');
bitmaps[4].loadfromfile('bitmap4.bmp');
bitmaps[5].loadfromfile('bitmap5.bmp');
end;
end.