试解答如下:
将ListBox控件的属性设置如下:
Style属性: lbOwnerDrawFixed
Color属性: clMoneyGreen (也可用白色)
2. 响应 ListBox 的事件,并编写代码如下:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
s: string;
begin
with TListBox(Control).Canvas do
begin
if (odSelected in State) or (odFocused in State) then
begin
Brush.Color := clNavy;
Font.Color := clWhite;
end
else
begin
Brush.Color := clMoneyGreen;
Font.Color := clBlack;
end;
case Index of
1:
Font.Style := [fsItalic];
2:
Font.Style := [fsBold];
3:
Font.Style := [fsBold, fsItalic];
end;
s := TListBox(Control).Items[Index];
DrawText(Handle, PChar(s), Length(s), Rect, DT_SingleLine or DT_VCenter);
end;
end;