当点击combobox时,弹出下拉框,点击当中任一项,显示的是蓝颜色的条子,怎样才能把蓝颜色的条子变成红颜色的条子。

解决方案 »

  1.   

    把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 := clRed;
        end;
        FillRect(Rect);
        TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Items[Index]);
      end;
    end;