文章目录
Listbox中显示位图
提示:这里可以添加技术概要

核心源码
procedure CenterText(Cnv: TCanvas; Rect: TRect; S: string);
var
X, Y: Integer;
begin
X := (Rect.Right + Rect.Left - Cnv.TextWidth(S)) div 2;
Y := (Rect.Bottom + Rect.Top - Cnv.TextHeight(S)) div 2;
Cnv.TextOut(X, Y, S);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with ListBox1.Items do
begin
Clear;
ListBox1.Style := lbOwnerDrawVariable;
AddObject(‘Bitmap1’, Image1.Picture.Bitmap);
Self.DoubleBuffered := true;
end;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
Bitmap: TBitmap;
begin
with ListBox1 do
begin
Canvas.FillRect(Rect);
if Items.Objects[Index] <>

本文介绍了如何在DELPHI的Listbox组件中显示位图,并提供了核心源码实现。通过ListBox1DrawItem和ListBox1MeasureItem事件处理函数,实现了位图的绘制和文字居中对齐。
2956

被折叠的 条评论
为什么被折叠?



