代码如下:
procedure TFrameAuction.RzListBoxMeasureItem(Control: TWinControl;
Index: Integer; var Height: Integer);
begin
Height:=82;//设置item的高度
end;
Index: Integer; var Height: Integer);
begin
Height:=82;//设置item的高度
end;
procedure TFrameAuction.RzListBoxDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
jpeg:TJPEGImage;
bmp:TBitMap;
root,cnode: IXMLNode;
icon: TIcon;
fname:string;
begin
root:=self.FXMLDoc.DocumentElement;
cnode:=root.ChildNodes[Index];
with (Control as TRzListBox).Canvas do begin
bmp:=TBitmap.Create;
jpeg:=TJPEGImage.Create;
if cnode.GetAttribute('photo')='' then begin
fname:=ExtractFilePath(Application.ExeName)+'images\none.jpg';
end else begin
fname:=ExtractFilePath(Application.ExeName)+'images\'+root.GetAttribute('id')+'-'+cnode.GetAttribute('photoid')+'-'+cnode.GetAttribute('photo');
if not FileExists(fname) then
fname:=ExtractFilePath(Application.ExeName)+'images\none.jpg';
end;
jpeg.LoadFromFile(fname);
with bmp do
begin
PixelFormat:=pf24bit;
Height:=60;
Width:=self.RzListBox.Width;
Canvas.Brush.Color:=$00F0EDE6;
Canvas.FillRect(Canvas.ClipRect);
Canvas.StretchDraw(Bounds(0,0,80,60), jpeg);
end;
FillRect(Rect);
Draw(Rect.Left+1, Rect.Top + 1,bmp);
icon:=TIcon.Create;
if cnode.GetAttribute('status')='1' then
self.ImageListStatus.GetIcon(8,icon)
else if cnode.GetAttribute('status')='3' then
self.ImageListStatus.GetIcon(2,icon)
else if cnode.GetAttribute('status')='2' then begin
if cnode.GetAttribute('bargainflag')='0' then
self.ImageListStatus.GetIcon(6,icon)
else
self.ImageListStatus.GetIcon(4,icon)
end else if cnode.GetAttribute('status')='0' then begin
if root.GetAttribute('activeitem')=cnode.GetAttribute('itemid') then
self.ImageListStatus.GetIcon(0,icon);
end;
Draw(Rect.Left+1+80+5,Rect.Top+22,icon);
TextOut(1,Rect.Top+64,cnode.GetAttribute('no')+'号:'+cnode.GetAttribute('itemtitle'));
end;
icon.Free;
bmp.Free;
jpeg.Free;
end;
Rect: TRect; State: TOwnerDrawState);
var
jpeg:TJPEGImage;
bmp:TBitMap;
root,cnode: IXMLNode;
icon: TIcon;
fname:string;
begin
root:=self.FXMLDoc.DocumentElement;
cnode:=root.ChildNodes[Index];
with (Control as TRzListBox).Canvas do begin
bmp:=TBitmap.Create;
jpeg:=TJPEGImage.Create;
if cnode.GetAttribute('photo')='' then begin
fname:=ExtractFilePath(Application.ExeName)+'images\none.jpg';
end else begin
fname:=ExtractFilePath(Application.ExeName)+'images\'+root.GetAttribute('id')+'-'+cnode.GetAttribute('photoid')+'-'+cnode.GetAttribute('photo');
if not FileExists(fname) then
fname:=ExtractFilePath(Application.ExeName)+'images\none.jpg';
end;
jpeg.LoadFromFile(fname);
with bmp do
begin
PixelFormat:=pf24bit;
Height:=60;
Width:=self.RzListBox.Width;
Canvas.Brush.Color:=$00F0EDE6;
Canvas.FillRect(Canvas.ClipRect);
Canvas.StretchDraw(Bounds(0,0,80,60), jpeg);
end;
FillRect(Rect);
Draw(Rect.Left+1, Rect.Top + 1,bmp);
icon:=TIcon.Create;
if cnode.GetAttribute('status')='1' then
self.ImageListStatus.GetIcon(8,icon)
else if cnode.GetAttribute('status')='3' then
self.ImageListStatus.GetIcon(2,icon)
else if cnode.GetAttribute('status')='2' then begin
if cnode.GetAttribute('bargainflag')='0' then
self.ImageListStatus.GetIcon(6,icon)
else
self.ImageListStatus.GetIcon(4,icon)
end else if cnode.GetAttribute('status')='0' then begin
if root.GetAttribute('activeitem')=cnode.GetAttribute('itemid') then
self.ImageListStatus.GetIcon(0,icon);
end;
Draw(Rect.Left+1+80+5,Rect.Top+22,icon);
TextOut(1,Rect.Top+64,cnode.GetAttribute('no')+'号:'+cnode.GetAttribute('itemtitle'));
end;
icon.Free;
bmp.Free;
jpeg.Free;
end;
运行结果如下: