微信漏洞免费领取1000:关于ListBox的另一个问题

来源:百度文库 编辑:高校问答 时间:2024/04/27 23:48:03
怎样让ListBox里显示的字呈现不同的颜色,可以做到吗?
比如有两个ListBox,一个里面有一些名字,另一个是空的,当我向那个空的的ListBox里加入一些名字的时候,如果加入的和第一个里的一样,那么第一个ListBox里的那个名字就会变成另一种颜色,而不同的不会变
在VB6.0里ListBox不存在OnChange事件或lbOwnerDrawVariable属性啊

把ListBox的Style属性设为lbOwnerDrawVariable
然后自己画其中的每一项

我给你个演示的代码

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
Brush.Color:=clblack;
FillRect(Rect);
if Index mod 2=0 then
Font.Color := clLime
else
Font.Color := clwhite;
TextOut(Rect.Left,REct.Top,listbox1.Items[index]);
end;
end;

你可以在LISTBOX的ONCHANGE事件里面写关于LISTBOX控件字体FRONT的颜色COLOR属性进行修改