⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delp009.html

📁 对于学习很有帮助
💻 HTML
字号:
<html><!-- #BeginTemplate "/Templates/fwolf001.dwt" -->
<head>
<!-- #BeginEditable "doctitle" --> 
<title>独孤之所 - 如何在ListView控件中绘底图</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!-- #EndEditable --> 
<style type="text/css">
<!--
body {  font-family: "宋体"; font-size: 9pt}
td {  font-family: "宋体"; font-size: 9pt}
a:hover {  text-decoration: underline}
a {  text-decoration: none}
input {  font-family: "宋体"; font-size: 9pt}
select {  font-family: "宋体"; font-size: 9pt}
-->
</style>
</head>


<body>
<!-- #BeginEditable "2%C7%F8" --> <!-- #EndEditable -->
<table width="584" border="0" align="center" cellspacing="1">
  <tr> 
    <td width="582"> 
      <div align="center"><!-- #EndEditable --></div>
    </td>
  </tr>
  <tr> 
    <td width="582"><font size="3"><!-- #BeginEditable "%CE%C4%B1%BE%C7%F8" --> 
      <center>
        <font color="#0000c0"> <font color="#FF3333">如何在ListView控件中绘底图</font><br>
        </font>重庆市巴南区 <br>
        周剑峰 
      </center>
      </font>
      <p><font color="#ffffff"><font size="3">----</font></font> <font size="3"> ListView控件是Windows程序开发中的常用控件, 利用它可以把需要用户进行选择操作的多个项目在窗口中以列表的方式显示,  
        每一个项目可以有它的小图标和大图标, 从而可以改善程序的用户界面, 方便用户操作.</font>  
      <p><font size="3"><font color="#ffffff">----</font> 为了使程序的界面更美观, 我们还可以在ListView控件中绘制底图,  
        正如我们可以为窗口绘制底图一样. 在Delphi中, 为ListView控件绘制底图是非常容易的, 它为我们提供有OnCustomDraw事件,  
        专门用于处理用户自定义的绘制, 在该事件中编写程序, 可以在绘制ListView的各个项目之前, 先执行该事件程序在ListView的画布(Canvas)上绘制我们自己的图形.</font>  
      <p><font size="3"><font color="#ffffff">----</font> 下面是在ListView控件中绘底图的一个小程序, 其运行结果如下图所示(略)</font>  
      <p><font size="3"><font color="#ffffff">----</font> 源程序如下:</font>  
      <pre><font size="3">
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 &lt; Height do begin
    X := 0;
    while X &lt; 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.
</font></pre>
      <!-- #EndEditable --></td>
  </tr>
  <tr>
    <td width="582"><font size="3"><!-- #BeginEditable "%B1%B8%D7%A2" --></font><!-- #EndEditable --></td>
  </tr>
</table>
</body>
<!-- #EndTemplate --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -