• 网络学院
  • IT资讯
  • 操作系统
  • 网络技术
  • 软件应用
  • 办公软件
  • 编程技术
  • 网站架设
  • 数据库类
  • 平面设计
  • 多媒体类
  • 游戏资讯
  • 教学论文
  • 认证考试
Delphi学习:在Listbox加背景图
  站点:
  • 首 页
  • 最新软件
  • 文章教程
  • 国内软件
  • 国外软件
  • 绿色软件
  • 源码下载
  • 字体下载
Delphi学习:在Listbox加背景图
软件发布 Delphi学习:在Listbox加背景图
网络软件 系统工具 应用软件 联络聊天 图形图像 多媒体类 行业软件 游戏娱乐 编程开发 安全相关 教育教学 数码软件 绿软下载
热门软件: QQ 瑞星 pplive e话通 木马克星 千千静听 office2000 五笔字根 Photoshop 视频分割
返回文章教程首页 >> 编程技术 >> Delphi教程 >> Delphi学习:在Listbox加背景图

Delphi学习:在Listbox加背景图

添加时间: 2006-2-25 7:43:26  作者: Delphi教程  阅读次数:117   来源: http://www.d9soft.com

       

  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);

  ComboBox1.Items.AddObject('Bitmap4: Key', TheBitmap4);
  ComboBox1.Items.AddObject('Bitmap5: Tools', TheBitmap5);
  ListBox1.Items.AddObject('Bitmap1: Globe', TheBitmap1);
  ListBox1.Items.AddObject('Bitmap2: Video', TheBitmap2);
  ListBox1.Items.AddObject('Bitmap3: Gears', TheBitmap3);
  ListBox1.Items.AddObject('Bitmap4: Key', TheBitmap4);
  ListBox1.Items.AddObject('Bitmap5: Tools', TheBitmap5);
  
  end;
  
  procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  begin
  TheBitmap1.Free;
  TheBitmap2.Free;
  TheBitmap3.Free;
  TheBitmap4.Free;
  TheBitmap5.Free;
  end;
  
  procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
  var
  Bitmap: TBitmap;
  Offset: Integer;
  begin
  with (Control as TComboBox).Canvas do
  begin
  FillRect(Rect);
  Bitmap := TBitmap(ComboBox1.Items.Objects[Index]);
  if Bitmap <> nil then
  begin
  BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
  Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
  Bitmap.Height), clRed);
  Offset := Bitmap.width + 8;
  end;
  { display the text }
  TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index])
  end;
  end;
  
  procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index:
  Integer; var Height: Integer);
  begin
  height:= 20;
  end;
  
  procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
  var
  Bitmap: TBitmap;
  Offset: Integer;
  begin
  with (Control as TListBox).Canvas do
  begin
  FillRect(Rect);
  Bitmap := TBitmap(ListBox1.Items.Objects[Index]);
  if Bitmap <> nil then
  begin
  BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
  Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
  Bitmap.Height), clRed);
  Offset := Bitmap.width + 8;
  end;
  { display the text }
  TextOut(Rect.Left + Offset, Rect.Top, Listbox1.Items[Index])
  end;
  end;

  procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
  begin
  height:= 20;
  end;
  
  end.

  //该窗体的DFM文件
  
  object Form1: TForm1

  Left = 211
  Top = 155
  Width = 435
  Height = 300
  Caption = 'Form1'
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  PixelsPerInch = 96
  OnClose = FormClose
  OnCreate = FormCreate
  TextHeight = 16
  object ComboBox1: TComboBox
  Left = 26
  Top = 30
  Width = 165
  Height = 22
  Style = csOwnerDrawVariable
  ItemHeight = 16
  TabOrder = 0
  OnDrawItem = ComboBox1DrawItem
  OnMeasureItem = ComboBox1MeasureItem
  end
  object ListBox1: TListBox
  Left = 216
  Top = 28
  Width = 151
  Height = 167
  ItemHeight = 16
  Style = lbOwnerDrawVariable
  TabOrder = 1
  OnDrawItem = ListBox1DrawItem
  OnMeasureItem = ListBox1MeasureItem
  end
  end

 

上下文章:

 

上一篇文章: Delphi单元文件详解 下一篇文章: Delphi7目录结构----初学者参考

相关文章:

  • 是时候告别系统白屏 让窗口背景靓起来
  • Photoshop给宝宝照片调色及背景美化
  • 学习Ruby-Web程序开发的10条理由
  • Fireworks教程:美女照片超绚背景
  • 解KMP看电影背景声大说话声小问题

相关软件:

  • Turbo C for Windows 集成实验与学习环境 V6.11
  • InfoPower for Delphi 5 V2000.17
  • 汇编语言学习工具 3.6
  • EnglishField英语学习软件 7.8
  • 限时英语(初中英语学习软件) 6.4
  • 英语学习王 V2007 Build 1221 真人发音版

 

快速导航

  • 网络学院
  • 精品汇聚
  • 字体下载
  • 教程下载
  • ASP源码
  • PHP源码
  • Net源码
  • JSP 源码

编程技术分类导航

  • ASP & ASP.NET教程
  • PHP教程
  • JSP教程
  • C/C++教程
  • VB & VB.NET教程
  • VC教程
  • Delphi教程
  • BCB教程
  • VFP教程
  • PB教程
  • JAVA教程
  • XML教程
  • C#教程
  • CGI教程

本类经典文章推荐

  • Delphi的两个实用技巧(1)播放Flash
  • Delphi的两个实用技巧(2)巧用Wind...
  • delphi实例编程之--制作可随处拖放...
  • 关于VisiBroker For Delphi的使用...
  • 关于VisiBroker For Delphi的使用...
  • 关于VisiBroker For Delphi的使用...
  • 在线播放器DIY
  • Delphi让你发送Flash电子邮件
  • 在窗口标题区添加按钮
  • 用Delphi 6编程实现自动标注汉语拼...

Delphi教程阅读排行

  • Delphi7从入门到精通之历数Delphi...
  • Delphi的两个实用技巧(1)播放Flash
  • Delphi7从入门到精通之认识Delphi...
  • delphi实例编程之--制作可随处拖放...
  • Delphi控件,我们也可以(1)
  • Delphi的两个实用技巧(2)巧用Wind...
  • Spcomm串口控件的例程
  • 在线播放器DIY
  • Delphi控件,我们也可以(2)
  • 用Delphi + DirectX开发简单RPG游...

编程技术阅读总排行

  • VB入门教程之一
  • Java连接数据库实例
  • VC++之List Box/Check List Box控...
  • 第二章 PowerBuilder 入门之创建新...
  • VC++ List Ctrl控件
  • 第一章 什么是PowerBuilder
  • VC++ Combo Box/Combo Box Ex控件
  • 学C++不得不看的一篇文章
  • VB入门教程之二
  • VC++之Button控件

广告位置

字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 回到顶部

关于我们 | 版权声明 | 免责条款 | 广告联系 | 软件发布 | 下载帮助 | 下载排行 | 网站地图 | 特别鸣谢 | 友情连接

copyright; 2005-2008 D9soft.com 第九软件网 版权所有