在CheckListBox中我有很多行。但我只想把某一行的字体颜色设置为红色,怎么实现呢?
谢谢

解决方案 »

  1.   

    Style = csOwnerDrawVariable
    OnDrawItem
    OnMeasureItem
      

  2.   

    procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
      TempColor: TColor;
    begin
      if odFocused in State then begin
          CheckListBox1.Canvas.Brush.Color := clHighlight;
          TempColor := clRed;
      end else begin
        CheckListBox1.Canvas.Brush.Color := CheckListBox1.Color;
        TempColor := clBlack;
      end;  CheckListBox1.Canvas.FillRect(Rect);  CheckListBox1.Canvas.Font.Color := TempColor;
      CheckListBox1.Canvas.TextOut(Rect.Left, Rect.Top, CheckListBox1.Items[Index]);
    end;procedure TForm1.CheckListBox1MeasureItem(Control: TWinControl;
      Index: Integer; var Height: Integer);
    begin
      Height := 18;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      with CheckListBox1 do begin
        Style := lbOwnerDrawVariable;
        Items.Add('aaaaaaaa');
        Items.Add('bbbbbbbb');
      end;
    end;