如何做出下面的效果?
就是一行文本显示不下来的时候,后面用...代替?
解答:使用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 ;