|
질문하신 부분의 오류는 제가 C++ Builder의 도움말을 복사해 오면서 형변환을 잘못해서 나온 것
같습니다.(꾸벅!)
pBitmap = (Graphics::TBitmap *)((TListBox *)Control)->Items->Objects[Index];
을
pBitmap = (Graphics::TBitmap *)((TCheckListBox *)Control)->Items->Objects[Index];
로 바꿔서 사용해 보시기 바랍니다.
참고로 TStrings->Objects는 AddObject()등을 이용한 경우에 사용하게 되는 Property이므로
님께서 CheckListBox1->Items->AddObject()를 사용하여 Object를 추가한 경우
(또는 직접 Objects에 자료를 넣은 경우)가 아니라면
pBitmap = (Graphics::TBitmap *)((TCheckListBox *)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;
}
을 지우시고 사용하셔도 될 것 같습니다 (Items->Object에 Graphics::TBitmap 형 자료를
추가해서 사용하는 경우라면 위 코드를 그대로 사용하시면 됩니다. ^_^;;)
참고로 아래는 TListBox의 내용을 복수 선택한 후 Button1을 누르면 CheckListBox1에 추가하는 예 입니다.
행복하세요.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
CheckListBox1->Items->Clear();
CheckListBox1->Style = lbOwnerDrawFixed;
ListBox1->MultiSelect = true; // ListBox1의 항목을 복수 선택 가능토록 설정
ListBox1->Items->Clear();
ListBox1->Items->Add( "C++Builder Channel" ); // 항목 추가
ListBox1->Items->Add( " Q & A" );
ListBox1->Items->Add( " FAQ" );
ListBox1->Items->Add( " Tip'N Tricks" );
ListBox1->Items->Add( " Tutorial" );
ListBox1->Items->Add( " Resources" );
ListBox1->Items->Add( " Components" );
ListBox1->Items->Add( " Messenger Project" );
ListBox1->Items->Add( "Home Channel" );
ListBox1->Items->Add( " 헤드라인 뉴스" );
ListBox1->Items->Add( " IT 뉴스" );
ListBox1->Items->Add( " 공지사항" );
ListBox1->Items->Add( " 자유게시판" );
ListBox1->Items->Add( " Happy!BREAK" );
ListBox1->Items->Add( " 구인/구직" );
ListBox1->Items->Add( " 건의사항" );
ListBox1->Items->Add( " 운영진 게시판" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckListBox1ClickCheck(TObject *Sender)
{
CheckListBox1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckListBox1DrawItem(TWinControl *Control,
int Index, TRect &Rect, TOwnerDrawState State)
{
int Offset = 2;
TCanvas *pCanvas = ((TListBox *)Control)->Canvas;
pCanvas->FillRect(Rect);
/* 이 프로그램에선 사용하지 않는 부분이므로 주석 처리했음 (있어도 무방함).
Graphics::TBitmap *pBitmap=new Graphics::TBitmap;
pBitmap = (Graphics::TBitmap *)((TCheckListBox *)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]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// ListBox1에서 선택된 항목을 CheckListBox1에 넣음.
for( int nI = 0; nI < ListBox1->Items->Count; nI++ ) {
if( ListBox1->Selected[nI] ) {
CheckListBox1->Items->Add( ListBox1->Items->Strings[nI] );
}
}
}
---------------------------------------------------------------
하늘누리 님이 쓰신 글 :
:
: 답변해 주셔서 감사합니다.
:
: 에러 나는 부분은 아래와 같습니다.
: 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;
: : }
:
:
: ListBox1Click()에서 하려는 목적은
: ListBox1Click를 클릭했을 그것에 관련된 데이터를 동적으로 CheckListBox1에 뿌려주기 위한것입니다.
: 그리고 for 문으로 10번을 반복한는것과 Clear것은 예로 만든것입니다.
:
: 아직도 위쪽에 나는 에러때문에....흑흑.
:
: 그럼 행복하세요..
:
|