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

📄 072301_05.htm

📁 对于学习很有帮助
💻 HTM
字号:
<html>

<head>
<link REL="stylesheet" HREF="/style.css" TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算机世界日报:
具有不同字体的列表框
</title>
<!--***********-->
</head>

<body bgcolor="#FFFFFF" >














<p><br>
<font color="#b904e8"><b><em><a href="class.htm">返回</a></em></b></font>
<center>
<font color="#0000c0"><h2>
具有不同字体的列表框
</h2></font>
<h3>
赖立谦
<br>
[请作者提供详细的邮政地址]
</h3>
</center>
<p><font color="#ffffff">----</font>
一般情况下,列表框内所有项的字体、大小、颜色等属性都是一样的。但是我们可以通过编写简单的程序使得每一项都能有自己的字体、大小和颜色。为了对比,我们用了两个Listbox构件,Listbox1按一般情况显示,Listbox2显示的每一项都可以有自己的字体、大小、颜色。

<p><font color="#ffffff">----</font>
首先把Listbox2的style属性改为lbOwnerDrawVariable。然后分别编写它的OnDrawItem事件和OnDrawItem事件。下面就是Listbox2 的OnDrawItem事件和OnDrawItem事件的代码:
<pre>
procedure TForm1.ListBox2DrawItem(Control:
 TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with ListBox2.Canvas do
  begin
    FillRect(Rect);
    Font.Size := 12;
    if Index mod 2 =0 Then
    begin
      Font.Name := '宋体';
      Font.Color := Clred;
    end
    else
    begin
      Font.Name := '隶书';
      Font.Color := Clgreen;
    end;
TextOut(Rect.Left+1, Rect.Top+1,
 ListBox2.Items[Index]);
  end;
end;

procedure TForm1.ListBox2MeasureItem
(Control: TWinControl; Index: Integer;
  var Height: Integer);
begin
  with ListBox1.Canvas do
  begin
    Font.Size := 12;
    if Index mod 2 =0 Then
    begin
      Font.Name := '黑体';
      Font.Color := Clred;
    end
    else
    begin
      Font.Name := '隶书';
      Font.Color := Clgreen;
    end;
    Height := TextHeight('Wg') + 2;
  end;
end;
</pre>
<font color="#ffffff">----</font>
此程序在Windows95、Delphi4.0环境下运行通过。



 



<p align="right"><small><em>中国计算机世界出版服务公司版权所有</em></small> 
<br>
</p>
</body>
</html>

⌨️ 快捷键说明

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