是在DrawItem里写吗?但我不知怎么写,网上也找不到相关的,麻烦大家

解决方案 »

  1.   

    设ComboBox1的Style为csOwnerDrawVariable
    然后在它的DrawItem程序中:
    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      p:integer;
    begin
    p:=(combobox1.ItemHeight-combobox1.Canvas.TextHeight(combobox1.Items[Index])) div 2;
    combobox1.Canvas.TextOut(Rect.Left,Rect.Top+p,combobox1.Items[Index]);
    end;
    由于每个字符的实际高度不一样(如a与b,后者要比前者实际高些:ab),所以结果可能不会完全居中(如全部是text为aaaa的)
      

  2.   

    谢谢,还想问一个,就是如何去掉这个combobox被选中时的虚线框呢?