ListBox自绘,列表显示一系列图片

     最近本人做的项目中,需要将一系列图片列表显示到一个ListBox中,本人使用的raize套件中的RzListBox,这里讲的方法同样适用于这两种组件,首先设置ListBox的style为:lbOwnerDrawVariable,然后处理ListBox的MeasureItem与DrawItem事件。

      代码如下:
procedure TFrameAuction.RzListBoxMeasureItem(Control: TWinControl;
  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;

运行结果如下:






    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2007/07/28/834873.html,如需转载请自行联系原作者

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值