做好的繼承Class,我要如何放到元件盤上,與可顯示屬性的設定和事件的選寫
這是取至站上一篇文章做範例:
Unit1.cpp //---------------------------------------------------------------------------
#include
#pragma hdrstop #include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TButtonGroup *BG;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
BG = new TButtonGroup(this);
BG->Parent = Form1;
BG->Top = 10;
BG->Left = 10;
BG->Width = 200;
BG->Height = 200;
BG->Caption = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete BG;
}
//--------------------------------------------------------------------------- Unit2.cpp //---------------------------------------------------------------------------
#include
#pragma hdrstop #include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TButtonGroup::TButtonGroup(TComponent* Owner)
: TGroupBox(Owner)
{
//===========================================================================
// TButtonGroup 類別建構函式
//===========================================================================
Button1 = new TButton(this);
Button2 = new TButton(this);
Button3 = new TButton(this);
Button1->Parent = this;
Button2->Parent = this;
Button3->Parent = this;
Button1->OnClick = OnClick;
Button2->OnClick = OnClick;
Button3->OnClick = OnClick;
Button1->Height = 20;
Button2->Height = 20;
Button3->Height = 20;
Button1->Width = 80;
Button2->Width = 80;
Button3->Width = 80;
Button1->Top = 10;
Button2->Top = 40;
Button3->Top = 70;
Button1->Left = 10;
Button2->Left = 10;
Button3->Left = 10;
Button1->Caption = "Button1";
Button2->Caption = "Button2";
Button3->Caption = "Button3";
Button1->Enabled = true;
Button2->Enabled = false;
Button3->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TButtonGroup::OnClick(TObject *Sender)
{
//===========================================================================
// TButtonGroup 類別內事件函式
//===========================================================================
Button1->Enabled = false;
Button2->Enabled = false;
Button3->Enabled = false;
if(Sender==Button1)
Button2->Enabled = true;
if(Sender==Button2)
Button3->Enabled = true;
if(Sender==Button3)
Button1->Enabled = true;
}
//--------------------------------------------------------------------------- Unit2.h //---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
class TButtonGroup : public TGroupBox
{
__published:
TButton *Button1;
TButton *Button2;
TButton *Button3;
void __fastcall OnClick(TObject *Sender);
private:
public:
__fastcall TButtonGroup(TComponent* Owner);
};
//---------------------------------------------------------------------------
#endif