就是如何把Tbitmap加入到listview中去

解决方案 »

  1.   

    用ImageList啊。ListView有LargeImages、SmallImages可以与ImageList关联。
      

  2.   

    imagelist是固定大小的,我的意思是用自定义的位图
      

  3.   

    设定 Tlistitem的tag值为你的所想付给的值,不要说不行,我试过的
      

  4.   

    要符合你的要求,只能自己画。
    在listview.ondrawitem里写代码。我也不是很熟,还没写出程序。
      

  5.   

    终于实现了!!
    今天晚上装系统,耽误了时间。
    自己画每个item,
    属性设置:ListView1.ViewStyle:=vsList;ListView.OwnerDraw:=False;//这个不能为false
    然后我在items里面有两个item,一个为Baby,一个为Hello;
    然后她画图时就出发下列事件,画出了两幅大小不一的图。
    你的要求是实现了,但讨厌在于这个东西,你画图时要自己定位。
    所以要计算得很好,否则,画出来很丑。        
    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
      var Bitmap:TBitmap;
    begin
            if Item.Caption='Baby' then
            begin
                    Bitmap:=TBitmap.Create;
                    Bitmap.LoadFromFile('1.bmp');
                    ListView1.Canvas.Draw(0,0,Bitmap);
                    Bitmap.Free;
            end
            else
            begin
            if Item.Caption='Hello' then
            begin
                    Bitmap:=TBitmap.Create;
                    Bitmap.LoadFromFile('2.bmp');
                    ListView1.Canvas.Draw(0,100,Bitmap);
                    Bitmap.Free;
            end;
            end;
    end;
      

  6.   

    多谢ch81:
    半夜两点还在帮我的忙!
    我现在用的d3,没有 listview1.canvas 属性,我有点难过了
    不过我要装一下d5,看一看
    如果功能实现,一定加分!
      

  7.   

    d5能够实现,
    但是这样生成的图象无法执行我的双击事件
    我的意思是在我的listview里面,用图象取代了caption
    而且图象能够象item一样能够选择,响应双击事件
    这个功能能实现吗?
      

  8.   

    asgq(强子) 
    我如下的程序以实现了点击事件。点击后触发onmousedown事件,判断其位置,做出
    处理。你看如何?unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls;
    type
      TForm1 = class(TForm)
        ListView1: TListView;
        procedure ListView1CustomDrawItem(Sender: TCustomListView;
          Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
        procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
     var x1,y1:integer;
    implementation
    {$R *.dfm}
    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
      var Bitmap:TBitmap;
    begin
            Bitmap:=TBitmap.Create;
            If Item.Caption='Hello' then
            begin
                    Bitmap.LoadFromFile('1.bmp');
                    ListView1.Canvas.Draw(x1,y1,Bitmap);
                    Bitmap.FreeImage;
            end
            else
            begin
                    Bitmap.LoadFromFile('2.bmp');
                    ListView1.Canvas.Draw(0,0,Bitmap);
                    x1:=0;//Bitmap.Width;
                    y1:=Bitmap.Height;
            end;
            DefaultDraw:=False;
    end;
    procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
            if y>y1 then
            begin
                    ShowMessage('Hello');
            end;
            if y<y1 then
            begin
                    ShowMessage('Baby');
            end;
    end;
    end.
      

  9.   

    希望能和朋友们多交流!
    [email protected]
    [email protected]