//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TControlParent.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: TControlParent
// Method: Controls.TControl.Parent
// Method: Controls.TWinControl.InsertControl
// Method: Controls.TWinControl.RemoveControl

// BeginCode
/*
This example uses a button placed next to a group box. When the
user clicks the button, the group box becomes the parent of the
button, so the button moves inside the group box.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (Button1->Parent != GroupBox1) // second click?
  {
	RemoveControl(Button1);
    GroupBox1->InsertControl(Button1);
  }
}

/*
Note that it was necessary to remove the button from the Controls
property of the form before the button actually moves into the
group box. This code accomplishes the same thing:
*/

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Button2->Parent = GroupBox1;
}
// EndCode
// EndExample: TControlParent
//---------------------------------------------------------------------------
