我在窗体上放了listbox,imagelist,image
procedure TForm1.FormCreate(Sender: TObject); var
i:Integer ;
bmp:TBitmap ;
begin
listbox.Clear ;
for i:= 0 to ImageList.Count -1 do
begin
bmp:=TBitmap.Create ;
ImageList.GetBitmap(i,bmp) ;
ListBox.AddItem('头像'+inttostr(i),bmp);
end;end;
我如何实现一点listbox中的一项就能在image中显示对应的图片
procedure TForm1.FormCreate(Sender: TObject); var
i:Integer ;
bmp:TBitmap ;
begin
listbox.Clear ;
for i:= 0 to ImageList.Count -1 do
begin
bmp:=TBitmap.Create ;
ImageList.GetBitmap(i,bmp) ;
ListBox.AddItem('头像'+inttostr(i),bmp);
end;end;
我如何实现一点listbox中的一项就能在image中显示对应的图片
procedure TForm1.ListBox1Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
//Image1.Picture.LoadFromFile(ImageList1.);
Bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(ListBox1.ItemIndex, Bitmap);
Image1.Picture.Bitmap := Bitmap;
finally
Bitmap.Free;
end;
end;
一句,改为这样好点:
Image1.Picture.Bitmap.Assign(Bitmap);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(ListBox1.ItemIndex, Bitmap);
Image1.Picture.Bitmap.Assign(Bitmap);
finally
Bitmap.Free;
end;
end;
NewGraphic: TGraphic;
begin
NewGraphic := nil;
if Value <> nil then
begin
NewGraphic := TGraphicClass(Value.ClassType).Create;
NewGraphic.Assign(Value);
NewGraphic.OnChange := Changed;
NewGraphic.OnProgress := Progress;
end;
try
FGraphic.Free;
FGraphic := NewGraphic;
Changed(Self);
except
NewGraphic.Free;
raise;
end;
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap(ListBox1.Items.Objects[ListBox1.ItemIndex]);
Image1.Picture.Assign(Bitmap);
end;
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap(ListBox1.Items.Objects[ListBox1.ItemIndex]);
Image1.Picture.Assign(Bitmap);
end;如果要显示不同的图片:procedure TForm1.ListBox1Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(ListBox1.ItemIndex, Bitmap);
Image1.Picture.Bitmap.Assign(Bitmap);
finally
Bitmap.Free;
end;
end;