2012-03-16 10 views

Odpowiedz

14

O ile mi wiadomo, tylko obejście dla tego problemu jest ownerdraw combobox

Spróbuj kroki

  1. ustawić właściwość styl combobox do csOwnerDrawFixed
  2. W przypadku OnDrawItem użyj metod styli vcl, aby narysować elementy combobox.

Sprawdź ten przykładowy kod

uses 
Vcl.Styles, 
Vcl.Themes, 

procedure TForm115.ComboBox1DrawItem(Control: TWinControl; Index: Integer; 
const 
    ColorStates: array[Boolean] of TStyleColor = (scComboBoxDisabled, scComboBox); 
    FontColorStates: array[Boolean] of TStyleFont = (sfComboBoxItemDisabled, sfComboBoxItemNormal); 
var 
    LStyles : TCustomStyleServices; 
begin 
    LStyles :=StyleServices; 
    with Control as TComboBox do 
    begin 
    Canvas.Brush.Color := LStyles.GetStyleColor(ColorStates[Control.Enabled]); 
    Canvas.Font.Color := LStyles.GetStyleFontColor(FontColorStates[Control.Enabled]); 

    if odSelected in State then 
    Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight); 

    Canvas.FillRect(Rect) ; 
    Canvas.TextOut(Rect.Left+2, Rect.Top, Items[Index]); 
    end; 
end; 

Więcej informacji można sprawdzić ten artykuł Vcl Styles and Owner Draw. Możesz także użyć jednostki Vcl.Styles.OwnerDrawFix (część vcl-styles-utils project), która obejmuje zestaw procedur rysowania właściciela dla komponentów takich jak TListBox, TComboBox i TListView.

Powiązane problemy