关于超想
本站导航
邮件列表
  首页 | 本站产品 | Delphi资料 | 免费资源 | 程序人生 | 软件工程 | 网站设计 | 推荐网站
你所在的位置 -> 主页 -> 超想软件 -> 编程资料 -> delphi -> 开发技巧 -> 构件使用 ->详细
相关内容  
 
 
在Delphi程序中应用IE浏览器控件
 
【新品推荐】

  详细内容
 

具有不同字体的列表框
作者: 评价: 上站日期: 2001-09-04
内容说明:
来源:

一般情况下,列表框内所有项的字体、大小、颜色等属性都是一样的。但是我们可以通过编写简单的程序使得每一项都能有自己的字体、大小和颜色。为了对比,我们用了两个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 -> 开发技巧 -> 构件使用 ->详细
  首页 | 本站产品 | Delphi资料 | 免费资源 | 程序人生 | 软件工程 | 网站设计 | 推荐网站
声明:本站内容除注明原创以外均从网上摘抄,如有侵权请指明。
  如果您对我们的网站有什么意见或者建议,请与我们联系
powered by 建站易上手- V2.0