|
CheckListBox의 Font 색상을 변경하기 위해선
먼저 CheckListBox의 Style을 lbOwnerDrawFixed로 바꾸시고
OnDrawItem Event를 이용해서 Canvas에 그려 주심 됩니다.
아래는 C++ Builder Help에 있는 예제중 일부를 변경헤서 처리한 것 입니다.
알맞게 변경/추가해서 사용하시기 바랍니다.
행복하세요.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "tFontColor.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
CheckListBox1->Style = lbOwnerDrawFixed;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
CheckListBox1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckListBox1DrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{
Graphics::TBitmap *pBitmap;
int Offset = 2;
TCanvas *pCanvas = ((TListBox *)Control)->Canvas;
pCanvas->FillRect(Rect);
pBitmap = (Graphics::TBitmap *)((TListBox *)Control)->Items->Objects[Index];
if (pBitmap)
{
pCanvas->BrushCopy(Bounds(Rect.Left + Offset, Rect.Top, pBitmap->Width, pBitmap->Height),
pBitmap, Bounds(0, 0, pBitmap->Width, pBitmap->Height), clRed);
Offset += pBitmap->Width + 4;
}
if( CheckListBox1->Checked[Index] ) {
// Checked 상태인 경우 Font 색상을 변경함.
pCanvas->Font->Color = clRed;
}
else {
// Font 정보를 그대로 유지하기 위하여 아무 처리도 하지 않음.
}
pCanvas->TextOut( Rect.Left + Offset, Rect.Top, ((TListBox *)Control)->Items->Strings[Index]);
}
---------------------------------------------------------------------------
하늘누리 님이 쓰신 글 :
: 안녕하세요
: 초보..입니다.
:
: CheckListBox에서 체크된 아템(문자열)을 폰트크기와 색을 변경시켜려고 하는데
: 어떻게 해야되는지 알려주세요...
:
:
|