procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var s:String;
begin
with ComboBox1.Canvas do
begin
FillRect(Rect);
s:=ComboBox1.Items[Index];
s:=Copy(s,1,POS('|',s)-1);
TextOut(Rect.Left, Rect.Top,s);
end;
end;
给你一个变通的方法,试验通过:
constructor TMyCustomComboBox.Create(AOwner: TComponent);
begin
inherited;
Style := csOwnerDrawFixed;
end;
procedure TMyCustomComboBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
inherited;
if odComboBoxEdit in State then // 在Edit中
begin
Canvas.FillRect(Rect);
if Index >= 0 then
Canvas.TextOut(Rect.Left + 2, Rect.Top, Copy(Items[Index], 3, MaxInt));
end;
end;