zoukankan      html  css  js  c++  java
  • 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;

    运行结果如下:
  • 相关阅读:
    stmt.executeQuery不执行解决办法
    可变参数
    深度理解JVM
    JDBC 基础入门
    Flask中Mysql数据库的常见操作
    Flask与mysql数据库字段类型的区别以及基本用法
    Flask里面session的基本操作
    Flask里面的cookie的基本操作
    Flask表单(form)的应用
    Flask网页模板的入门
  • 原文地址:https://www.cnblogs.com/taobataoma/p/834873.html
Copyright © 2011-2022 走看看