|
TGroupBox::Tag 속성을 이용해서 하실 수 있습니다.
Tag가 Integer 니까 간단하게 인덱스로 사용하거나, 구조체의 포인터로 사용할 수 있습니다.
//header ------------------------------------------------------------
#ifndef untMainH
#define untMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
TGroupBox * GroupBox1[10];
TImage * image[10];
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall GroupBox1Click(TObject *Sender);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//source ------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "untMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
int i;
int j;
j=20;
for (i=0;i<3;i++)
{
GroupBox1[i]= new TGroupBox(this);
GroupBox1[i]->Caption = "GroupBox" + IntToStr(i+1);
GroupBox1[i]->Parent=Form1;
GroupBox1[i]->Left=20;
GroupBox1[i]->Top=j;
j=j+200;
GroupBox1[i]->Height =200;
GroupBox1[i]->Width=200;
///////////////////////////////////////////////////
GroupBox1[i]->Tag = i; // 그룹박스들의 고유한 인덱스를 지정합니다.
GroupBox1[i]->OnClick = GroupBox1Click;
///////////////////////////////////////////////////
GroupBox1[i]->Visible =True;
image[i]=new TImage(GroupBox1[i]);
image[i]->Parent = GroupBox1[i];
image[i]->Left=10; // Parnet가 GroupBox가 되니까, Left,Top을
image[i]->Top=20; // GroupBox내부에서의 상대적인 Position으로 줍니다.
image[i]->Height =100;
image[i]->Width=100;
image[i]->Picture->LoadFromFile("e:\\어린이1.bmp");
image[i]->Visible =True;
image[i]->AfterConstruction();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GroupBox1Click(TObject *Sender)
{
ShowMessage( ((TGroupBox*)Sender)->Caption ); // Sender는 이벤트를 발생시킨 그룹박스를 가리킵니다.
//////////////////////////////////////////////
// 그룹박스를 생성하면서 TGroupBox::Tag를 각각의 인덱스로 지정했습니다.
// 이 부분에서 그 Tag 값을 이용해서 이벤트를 발생시킨 그룹박스가 어떤 녀석인지 알 수 있습니다.
//////////////////////////////////////////////
}
//---------------------------------------------------------------------------
|