listbox有什么办法可以让字体随意更改颜色
绍兴老鼠 2017-10-21 08:55:51 具体是这样的:
procedure TForm2.ListBox2DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
s: string;
rec:Trect;
begin
with TListBox(Control).Canvas do
begin
//if (odSelected in State) or (odFocused in State) then
//begin
//Brush.Color := clred;
case txtcolor of
1:Font.Color := clwindowtext;
2:Font.Color := clred;
3:Font.Color := cllime;
4:Font.Color := clfuchsia;
5:Font.Color := clblue;
end;
font.Name:='MS Sans Serif';
font.Size:=8;
font.Height:=-11;
//s := TListBox(Control).Items[Index];
//DrawText(Handle, PChar(s), Length(s), rect, DT_SingleLine or DT_VCenter);
ListBox2.Canvas.FillRect(Rect);
ListBox2.Canvas.TextOut(Rect.Left,Rect.Top,ListBox2.Items.Strings[Index]);
end;
end;
然后我在其他地方根据需要改变这个txtcolor值,但是结果得到的是全部区域都变成了指定的颜色。
我还试图改变rect,根据出现了这一行的itemindex*行高来指定rect(),这样得到的是只打印了这一行文字,其他的都不见了。
我的理解是重绘把其他的一起重绘掉了。
哪位前辈有什么方法吗。不能指定行来设置颜色,我是一个游戏根据战斗情况发送不同颜色的提示。
谢谢大家!
或者还有没有更快捷的控件呢。
我本来想用delphix里面的画布显示的,但是单步走吓死人,所以不到那步我也不想用它。