手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

Delphi字符串列表及应用(二)

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

ListBox1 MeasureItem(Control: TwinControl;Index: Integer; var Height: Integer);

  例程中响应OnMeasureItem事件的代码如下:  

procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;

var Height: Integer);

begin

with ListBox1.Canvas do

begin

Font.Name := ListBox1.Items[Index];

Height := TextHeight('A');

end;

end; 

procedure TForm1.TabSetMeasureTab(Sender: TObject; Index: Integer;

var TabWidth: Integer);

var

BitmapWidth: Integer;

begin

BitmapWidth := TBitmap( TabSet1.Tabs.Objects[Index]).Width;

Inc(TabWidth, 2 BitmapWidth);

end; 

 在OnMeasureItem事件发生后,Windows激发一个叫OnDrawItem的事件,这个事件也随部件名称不同而不同,常见的有OnDrawItemOnDrawTabOnDrawCell

  OnMeasureItem的声明如下:

  DrawItem( Control: TWinControl; Index: integer; Rect: TRect; State: TOwnerDraw); 

其中Control是包含项目的部件引用

    Index 是项目的索引号

    Rect  是绘制的矩形

    State 是项目的状态,如选中,得到焦点等。 

  在例程的列表框中,所列项目是屏幕支持的各种字体名称,当列表框发生OnDrawItem事件时,程序把输出字体设置成该项目所代表的字体,因而列表框的项目呈现出不同的字体,其代码如下:  

procedure TForm1.DrawItem(Control: TWinControl; Index: Integer;

Rect: TRect; State: TOwnerDrawState);

begin

with ListBox1.Canvas do

begin

FillRect(Rect);

Font.Name := ListBox1.Items[Index];

TextOut(Rect.Left, Rect.Top, ListBox1.Items[Index]);

end;

end;

  在Tabset部件中,则把位图与文本同时输出,其代码如下: 

procedure TForm1.TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas;

R: TRect; Index: Integer; Selected: Boolean);

var

Bitmap: TBitmap;

begin

Bitmap := TBitmap(TabSet1.Tabs.Objects[Index]);

with TabCanvas do

begin

Draw(R.Left, R.Top 4, Bitmap);

TextOut(R.Left 2 Bitmap.Width,

R.Top 2, TabSet1.Tabs[Index]);

end;

end;

上一篇: Delphi文本编辑器的设计(一)
下一篇: Delphi文本编辑器的设计(二)

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!