📄 026.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>-->DELPHI专题--用户界面-->如何在ListView控件中绘底图</TITLE>
<META NAME="keywords" CONTENT=" DELPHI专题--用户界面 如何在ListView控件中绘底图">
<META NAME="description" CONTENT=" - DELPHI专题--用户界面 - 如何在ListView控件中绘底图">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<a href="index1.html">返回</a>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">如何在ListView控件中绘底图</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<BR>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> ListView控件是Windows程序开发中的常用控件,
利用它可以把需要用户进行选择操作的多个项目在窗口中以列表的方式显示,
每一个项目可以有它的小图标和大图标,
从而可以改善程序的用户界面, 方便用户操作. </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font>
为了使程序的界面更美观, 我们还可以在ListView控件中绘制底图,
正如我们可以为窗口绘制底图一样. 在Delphi中, 为ListView控件绘制底图是非常容易的,
它为我们提供有OnCustomDraw事件, 专门用于处理用户自定义的绘制,
在该事件中编写程序, 可以在绘制ListView的各个项目之前,
先执行该事件程序在ListView的画布(Canvas)上绘制我们自己的图形. </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 下面是在ListView控件中绘底图的一个小程序,
其运行结果如下图所示(略) </span></p>
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 源程序如下: </span></p>
<BR>
<pre><span style="font-size: 9pt">unit ListViewMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs,
ComCtrls, ImgList;
type
TForm1 = class(TForm)
ListView1: TListView;
ImageList1: TImageList;
procedure ListView1CustomDraw(Sender:
TCustomListView;
const ARect: TRect; var DefaultDraw:
Boolean);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bitmap1: TBitmap;
implementation
{$R *.DFM}
procedure TForm1.ListView1CustomDraw(Sender:
TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
var
x,y,w,h : LongInt;
begin
with Bitmap1 do begin
W := Width;
H := Height;
end;
Y := 0;
while Y < Height do begin
X := 0;
while X < Width do begin
ListView1.Canvas.Draw(X, Y, Bitmap1);
Inc(X, W);
end;
Inc(Y, H);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Bitmap1 := TBitmap.Create;
Bitmap1.LoadFromFile('backgray.bmp');
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Bitmap1.Free;
end;
end.
</span></pre>
<BR>
<hr color="#EE9B73" size="1" width="94%">
</TD>
</TR>
</table>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -