首页  编辑  

ListBox的...功能

Tags: /超级猛料/VCL/(Check|List|ComBo)BOX/   Date Created:

如何做出下面的效果?

就是一行文本显示不下来的时候,后面用...代替?

解答:使用OwnerDraw功能:设置ListBox的Style为OwnerDraw,然后在DrawItem里面写代码:

procedure TForm1 . ListBox1DrawItem ( Control : TWinControl ; Index : Integer ;  Rect : TRect ; State : TOwnerDrawState );

var

 s : string ;

begin

 s :=( Control as TListbox ). Items [ Index ];

 ListBox1 . Canvas . FrameRect ( RECT );

 DrawTextEx (( Control as TListbox ). Canvas . Handle , pchar ( s ), length ( s ), Rect , DT_END_ELLIPSIS , Nil );

end ;

img_5166.bmp (129.1KB)