CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

哪个组件能够像Listbox添加string那样添加bitmap?

楼主luyang821109(菜鸟)2006-03-04 21:57:36 在 Delphi / VCL组件开发及应用 提问

我想做个列表装图像,但listbox好像只能添加string类型的,有哪个组件能加bitmap类型的?或者有什么方法么? 问题点数:20、回复次数:4Top

1 楼unsigned(僵哥(发站内消息,请附上链接或问题说明,否则不予回复))回复于 2006-03-04 22:20:24 得分 0

ListBox也可以,它有一个方法AddObject是可以用来利用的,要不建议看看ImageList或者仿其样做一个.Top

2 楼luyang821109(菜鸟)回复于 2006-03-04 22:36:19 得分 0

我试了,listbox没有addobject这个方法,我想动态的添加bitmap,用不上ImageListTop

3 楼saien(精益求精)回复于 2006-03-04 23:17:12 得分 10

unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          ListBox1:   TListBox;  
          Button1:   TButton;  
          procedure   FormCreate(Sender:   TObject);  
          procedure   FormDestroy(Sender:   TObject);  
          procedure   ListBox1DrawItem(Control:   TWinControl;   Index:   Integer;  
              Rect:   TRect;   State:   TOwnerDrawState);  
          procedure   Button1Click(Sender:   TObject);  
      private  
          {   Private   declarations   }  
          bmp:TBitmap   ;  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
  begin  
      ListBox1.Style   :=   lbOwnerDrawVariable;  
      ListBox1.ItemHeight   :=   50;  
      bmp   :=   TBitmap.Create;  
      try  
          bmp.LoadFromFile('c:\windows\Rhododendron.bmp');  
           
      except  
          Raise;  
      end;  
  end;  
   
  procedure   TForm1.FormDestroy(Sender:   TObject);  
  begin  
      bmp.Free;  
  end;  
   
  procedure   TForm1.ListBox1DrawItem(Control:   TWinControl;   Index:   Integer;  
      Rect:   TRect;   State:   TOwnerDrawState);  
  var  
      bmpRect,TxtRect:TRect   ;  
  begin  
      //画图像  
      if   Index   <   0   then   Exit;  
      SetRect(BmpRect,Rect.Left,Rect.Top,(Rect.Right   div   2),Rect.Bottom);  
      SetRect(TxtRect,bmpRect.Right+1,Rect.Top,Rect.Right,Rect.Bottom);  
   
      with   TListBox(Control).Canvas   do  
      begin  
          StretchDraw(bmpRect,TBitmap(TListBox(Control).Items.Objects[index]));  
          TextOut(TxtRect.Left,((TxtRect.Bottom)   div   2)-(TextHeight('####')   div   2),TListBox(Control).Items.Strings[index])  
      end;  
      //画文字  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
  ListBox1.AddItem('TestBmp',bmp);  
  end;  
   
  end.  
  Top

4 楼unsigned(僵哥(发站内消息,请附上链接或问题说明,否则不予回复))回复于 2006-03-05 01:07:11 得分 10

//下面的代码没有释放对象,仅作参考.  
  ------------------------  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
        bmp:TBitmap;  
  begin  
        bmp:=TBitmap.Create;  
        //try  
              if   OpenPictureDialog1.Execute   then  
              begin  
                    bmp.LoadFromFile(OpenPictureDialog1.FileName);  
                    ListBox1.Items.AddObject(ExtractFileName(OpenPictureDialog1.FileName),TObject(bmp));  
              end;  
        //finally  
        //       bmp.Free;  
        //end;  
  end;  
   
  procedure   TForm1.ListBox1Click(Sender:   TObject);  
  begin  
        if   ListBox1.ItemIndex<0   then   Exit;  
        Image1.Picture.Assign(TBitmap(ListBox1.Items.Objects[ListBox1.ItemIndex]));  
   
  end;Top

相关问题

  • 怎么让一个BITMAP流在IMAGE组件里显示?
  • 不好意思,又碰到listbox组件的问题了!!!
  • 怎么动态的添叫listbox组件的值
  • 关于在listbox组件里取字段的问题
  • 程序中怎样取得Query组件中SQL(string)的内容?
  • 组件
  • 组件
  • 请教一下,为什么服务器组件(例如:listbox )怎么只有 ListBox_SelectedIndexChanged 方法?
  • (大富翁没人答,这里有吗?)组件开发相关: 设计的属性是string类型的,希望组件用户通过OpenDialog指定文件…………
  • 怎样保存用户对listbox组件文本的修改,使以后执行程序都可以看得到??

关键词

  • 添加
  • listbox
  • bitmap
  • tform
  • tobject
  • bmp
  • procedure
  • sender
  • 方法

得分解答快速导航

  • 帖主:luyang821109
  • saien
  • unsigned

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo