首先要把ComboBox的属性设定一下.
ComboBox1.Style = csOwnerDrawFixed //此属性下会执行到DrawItem Event
ComboBox1.ItemHeight = 32; //调整高度
ComboBox1.DropDownCount = 2;
再适当调整一下它的宽度。
procedure TFTSProduct.ComboBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
inherited;
ComboBox1.Canvas.Brush.Color := clWindow;
if odSelected in State then ComboBox1.Canvas.Brush.Color := clHighLight;
ComboBox1.Canvas.FillRect(Rect);
ImageList2.Draw(ComboBox1.Canvas, Rect.Left, Rect.Top, Index); //画图
ComboBox1.Canvas.TextOut(Rect.Left + 20,Rect.Top,ComboBox1.Items[Index]); //文字
end;
ListBox 类似