发信人: mengy (LEAR DLLS 命令时,将从内存中清除), 信区: BorlandDev
标 题: 具有不同字体的列表框
发信站: 哈工大紫丁香 (2001年03月13日17:49:22 星期二), 转信
具有不同字体的列表框 <<上一篇 >>下一篇
---- 一般情况下,列表框内所有项的字体、大小、颜色等属性都是一样的。但
是我们可以通过编写简单的程序使得每一项都能有自己的字体、大小和颜色。为了
对比,我们用了两个Listbox构件,Listbox1按一般情况显示,Listbox2显示的每
一项都可以有自己的字体、大小、颜色。
---- 首先把Listbox2的style属性改为lbOwnerDrawVariable。然后分别编写它的
OnDrawItem事件和OnDrawItem事件。下面就是Listbox2 的OnDrawItem事件和
OnDrawItem事件的代码:
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;
---- 此程序在Windows95、Delphi4.0环境下运行通过。
如果你有什么好的资料,可以寄给我哟:) <<回到首页 <<上一篇 >>下一篇
------------------------------------------------------------------------
--------
Delphi 技巧集
Copyright 1999.11 by 东子 Mail to me!
感谢广州视窗提供主页空间
--
大海无边天做岸
山登绝顶我为风
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.121]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.812毫秒