网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C/C++
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.如何取得Memo的行和列.
.用Delphi 开发数据库程序经验三则.
.了解C++异常处理的系统开支.
.《c语言程序设计》第一章: C语言.
.连接MYSQL数据库的方法及示例.
.C程序开发初级讲座之分支结构.
..
.C语言图形处理.
.C语言库函数(W类字母).
.C++箴言:争取异常安全的代码.
.送给初学者的礼物:C++游戏编程起.
.C++设计模式之Singleton.
.链表的c语言实现(九).
.lzw压缩算法的c语言实现.
.Delphi6函数大全(2).
.点灯游戏算法实现.
.点阵字模工具编程辅助效果示例.
.5.  运算符.
.MFC中几个有用的字符串操作函数.
.请高手讲讲C语言函数strtok()和m.

在Listboxes中加背景图

发表日期:2008-3-8


Delphi

1. 建立一个窗体

2. 放一个ComboBox和Listbox

3. 改变Component的Style为csOwnerDrawVariable和ListBox的Style为lbOwnerDrawVariabble。

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;

Th tmap3.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
上一篇:DBGrid中的下拉列表和查找字段编程方法 人气:511
下一篇:用游戏串起程序员的基本功之四 人气:455
浏览全部C/C++的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐