搜狐首页 - 新闻 - 体育 - 娱乐 - 财经 - IT - 汽车 - 房产 - 女人 - 短信 - 彩信 - 校友录 - 邮件 - 搜索 - BBS - 搜狗 
搜狐首页 >> 搜狐IT >> 数码天下 >> 网狐教程-搜狐IT >> 程序开发-网狐教程-搜狐IT >> Delphi
Delphi学习:在Listbox加背景图
IT.SOHU.COM  2004-05-13 14:19  作者: CSDN  转自: 太平洋电脑网
页面功能 【我来说两句】【我要“揪”错】【推荐】【字体: 】【打印】 【关闭

  1. 建立一个窗体
  2. 放一个ComboBox和Listbox 

  3. 改变Component的Style为csOwnerDrawVariable和ListBox的Style为lbOwnerDrawVariable。
  4. 声明5个TBitmap的全局变量
  5. 覆盖Form的OnCreate.
  6. 覆盖ComboBox的OnDraw.
  7. 覆盖ComboBox的OnMeasureItem.
  8. 释放资源在Form的OnClose.
  
  unit Ownerdrw;
  
  interface
  
  uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;
  
  type
  TForm1 = class(TForm)
  ComboBox1: TComboBox;
  ListBox1: TListBox;
  procedure FormCreate(Sender: TObject);
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
  procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
  procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
  procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
  
  private
  { Private declarations }
  
  public
  { Public declarations }
  
  end;
  
  var
  Form1: TForm1;
  TheBitmap1, TheBitmap2, TheBitmap3, TheBitmap4,
  TheBitmap5 : TBitmap;
  implementation
  
  {$R *.DFM}
  
  procedure TForm1.FormCreate(Sender: TObject);
  begin
  TheBitmap1 := TBitmap.Create;
  TheBitmap1.LoadFromFile('C:\delphi\images\buttons\globe.bmp');
  TheBitmap2 := TBitmap.Create;
  TheBitmap2.LoadFromFile('C:\delphi\images\buttons\video.bmp');
  TheBitmap3 := TBitmap.Create;
  TheBitmap3.LoadFromFile('C:\delphi\images\buttons\gears.bmp');
  TheBitmap4 := TBitmap.Create;
  TheBitmap4.LoadFromFile('C:\delphi\images\buttons\key.bmp');
  TheBitmap5 := TBitmap.Create;
  TheBitmap5.LoadFromFile('C:\delphi\images\buttons\tools.bmp');
  ComboBox1.Items.AddObject('Bitmap1: Globe', TheBitmap1);
  ComboBox1.Items.AddObject('Bitmap2: Video', TheBitmap2);
  ComboBox1.Items.AddObject('Bitmap3: Gears', TheBitmap3);

[1] [2] [3下一页 
页面功能 【我来说两句】【我要“揪”错】【推荐】【字体: 】【打印】 【关闭





ChinaRen - 繁体版 - 搜狐招聘 - 网站登录 - 帮助中心 - 设置首页 - 广告服务 - 联系方式 - 保护隐私权 - About SOHU - 公司介绍
Copyright © 2004 Sohu.com Inc. All rights reserved. 搜狐公司 版权所有

相关链接
  • 用Delphi编写后台监控软件(03/21 11:05)
  • 使用Delphi创建IIS虚拟目录(03/19 17:18)
  • 使用Delphi创建IIS虚拟目录(03/19 17:18)
  • 使用Delphi创建IIS虚拟目录(03/19 17:15)
  • DELPHI 技巧 - RichEdit使用技(03/17 09:46)
  • Delphi 技巧 - 使窗体部分可见(03/17 09:46)
  • Delphi 技巧改造HINT的输出方式(03/17 09:46)
  • Delphi编写网络程序的安全措施(03/17 12:44)
  • Delphi屏幕抓字技术揭密(03/18 01:20)
  • Delphi屏幕抓字技术揭密(03/18 01:20)

  •  ■ 我来说两句
    用  户:        匿名发出:
    请各位遵纪守法并注意语言文明。
     
    *经营许可证编号:京ICP00000008号
    *《互联网电子公告服务管理规定》
    *《全国人大常委会关于维护互联网安全的规定》
    短信内容:
    手 机
    自写包月5分钱/条 更多>>
    搜狐天气为你抢先报! 魔力占卜姻缘一线牵!
    金币不是赚的是抢的! 爱情玄机任由你游戏!
    猪八戒这样泡到紫霞! 帅哥一定要看的宝典!
    你受哪颗星星的庇护? 萨达姆最新关押照片!
    精彩彩信
    [和弦]欧若拉 一生有你
    沧海一声笑
    [音效]挪威的森林
    爆铃 MP3 G点图 动画
    [和弦]童话 你到底爱谁
    [原唱]一千年以后 断点
    [爆笑音效]赚钱拉 野花
    [串烧]张韶涵 潘玮柏
    精彩短信
    [和弦]小薇 好心分手
    [音效]当当当当 忘记


    搜狐商城
    ·家电|品牌风扇新品热销
    ·音乐|秦海璐幸福回味
    ·图书|《眼镜蛇事件》
    更多...