|
예 저도 말씀 한신대로 햇습니다만...색이 전체다가 바뀌어 지네요...그리고 보여주신 예제처럼 ListBox1DrawItem함수의 index값을 조건문에 주면 각 라인별로 색깔이 바뀌어 집니다..전 이 index값을 사용하는 것이 아니라..리스트 박스의 아이템에서 메세지 레벨이라는 값도 들어가집니다.이 메세지 레벨값을 보고 그 메세지 레벨에 해당하는 색을 설정하고 싶거든요..메세지 레벨의 값은 각 5개로 "L","M","H","E","F"로 다섯가지 입니다.그래서 전 아이템에서 이다섯개를 순서대로 0~4로 지정하여 그 해당값을 전역변수 tmp_level에 할당하고, 이를 ListBox1DrawItem함수에서 조건문에 사용하였습니다..근데 한 라인의 아이템의 색이 변하는것이아니라..전체가가 다 변해서...이 글을 올리게 되엇습니다..좀더 상세히 답변해 주시면 감사 하겠습니다.
유영인 [Chris] 님이 쓰신 글 :
: 아래 소스에는 문제가 없는 것 같네요. 아마도 다른 부분에서 실수를 하신게 아닌가 싶습니다.
: 혹시 Font를 지정하시고, Listbox 의 프로퍼티중, Style을 부분을 default 값인 lbStandard로 설정해 두시진 않으셨나요?
:
: Listbox 의 프로퍼티중, Style을 부분을 lbOwnerDrawFixed 이나 lbOwnerDrawVariable로 설정하셔야, DrawItem 이벤트를 사용하실 수 있습니다.
:
: 아래는 간단한 예제입니다.
:
:
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "Unit1.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
:
: ListBox1->Items->Add ("Hello");
:
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
: {
:
: switch(Index % 5) {
: case 0 :
: ListBox1->Canvas->Font->Color= clNavy;
: break;
: case 1 :
: ListBox1->Canvas->Font->Color= clMaroon;
: break;
: case 2 :
: ListBox1->Canvas->Font->Color= clOlive;
: break;
: case 3 :
: ListBox1->Canvas->Font->Color= clBlack;
: break;
: case 4 :
: ListBox1->Canvas->Font->Color= clTeal;
: break;
: }
:
: ListBox1->Canvas->TextRect(Rect, Rect.Left, Rect.Top, ListBox1->Items->Strings[Index]);
:
: }
: //---------------------------------------------------------------------------
:
:
:
: 김상훈 님이 쓰신 글 :
: : 리스트 박스에서 각 아이템의 덱스트 색깔이 각 조건에 의해서 바꾸어지도록 코딩을 햇는데..각 라인이 바뀌는 것이 아니라..전체가 다 바뀌어 집니다..어디가 잘 못 되었는지 선배님들의 많은 가르침을 기다리겠습니다...그럼 즐거운 주말이 돼세요...
: :
: : bool __fastcall TMsgForm::ReadMsg( void )
: : {
: : ....
: : ....
: : ....
: : tmp_level=....;
: : ...
: : }
: :
: : void __fastcall TMsgForm::ListBox1DrawItem(TWinControl *Control, int Index,
: : TRect &Rect, TOwnerDrawState State)
: : {
: : if( tmp_level == MSG_LVL_LOW){
: : ListBox1->Canvas->Font->Color= clWhite;}
: : else if( tmp_level == MSG_LVL_MED){
: : ListBox1->Canvas->Font->Color = clAqua;}
: : else if( tmp_level == MSG_LVL_HIGH){
: : ListBox1->Canvas->Font->Color = clYellow;}
: : else if( tmp_level == MSG_LVL_ERROR){
: : ListBox1->Canvas->Font->Color = clFuchsia;}
: : else if( tmp_level == MSG_LVL_FATAL){
: : ListBox1->Canvas->Font->Color = clRed;}
: :
: : ListBox1->Canvas->TextRect(Rect, Rect.Left, Rect.Top, ListBox1->Items->Strings[Index]);
: :
: : }
|