一个在Listbox中加入图片的问题??大家过年好!
在给Listbox中加入图片时,遇到的困难,下面是我的做法!
请问怎样才能把Jpg,ico等其他格式的加入进来~?
1、我先在SpeedButton1Click中做的事情
procedure TForm1.SpeedButton1Click(Sender: TObject);
VAR bitmap:Tbitmap;
txt:string;
begin
bitmap:=tbitmap.Create(self);
try
bitmap.LoadFromFile(DirectoryListBox1.Directory+'\'+Edit1.Text);
Except
bitmap:=nil;
end;
listbox1.Items.AddObject(Edit2.Text,bitmap);
end;
2在ListBox1MeasureItem中做的事情
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
Height:=20;
end;
3在ListBox1DrawItem中做的事情
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
VAR itmap:Tbitmap;
pos:Integer;
begin
with control as TListbox do
begin
canvas.FillRect(rect);
itmap:=Tbitmap(Items.Objects[index]);
pos:=0;
if itmap<>nil then
begin
canvas.brushcopy(bounds(rect.left+2,rect.top+2,itmap.Width,itmap.Height),itmap,bounds(0,0,itmap.width,itmap.height),clred);
pos:=itmap.Width+8
end;
canvas.TextOut(rect.left+pos,rect.Top,items[index]);
end;
end;
以上的能实现bitmap的图片,怎样加入其他格式的呢》》?