Q&A

  • 콤보박스에 관한 질문입니다(급합)
콤보박스의 각 인덱스에 있는 스트링의 글자색상을 변경할 수 있는지요?

예를들어

111

222

333 이라는 글자가 들어있을때

111의 글자색은 빨강

222의 글자색은 파랑

333의 글자색은 검정 식으로...









1  COMMENTS
  • Profile
    홍성락 2001.11.02 23:56
    한성철 wrote:

    > 콤보박스의 각 인덱스에 있는 스트링의 글자색상을 변경할 수 있는지요?

    > 예를들어

    > 111

    > 222

    > 333 이라는 글자가 들어있을때

    > 111의 글자색은 빨강

    > 222의 글자색은 파랑

    > 333의 글자색은 검정 식으로...

    /////////////////////////////////////////////////////////////////////////

    아래처럼 ComboBox의 DrawItem에 넣으면 되는데요

    문제는 ComboBox의 Style이 csOwnerDrawFixed 또는 csOwnerDrawVariable 이어야 합니다.

    이를 극복하려면 다른 방법도 있을듯합니다.



    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;

    Rect: TRect; State: TOwnerDrawState);

    var

    Color : TColor;

    begin

    if Index = 0 then Color := clRed

    else if Index = 1 then Color := clBlue

    else if Index = 2 then Color := clBlack

    else Color := clBlack;



    ComboBox1.Canvas.Font.Color := Color;

    ComboBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top , ComboBox1.Items.Strings[Index]);

    end;