给你一个简单的例子——
把ComboBox1的Style属性设为csOwnerDrawFixed,然后在OnDrawItem事件里——
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ComboBox1, ComboBox1.Canvas do begin
Font.Color := clWindowText;
Brush.Color := clWindow;
if odSelected in State then begin
Font.Color := clWhite;
Brush.Color := clBlue;
end else begin
if Index mod 2 = 0 then begin
Font.Color := clYellow;
Brush.Color := clRed;
end else begin
Font.Color := clLime;
Brush.Color := clBlack;
end;
end;
FillRect(Rect);
TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Items[Index]);
end;
end;