TControlParent (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a button placed next to a group box. When you click the button, the group box becomes the parent of the button, so the button moves inside the group box.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (Button1->Parent != GroupBox1) // Second click?
  {
	RemoveControl(Button1);
    GroupBox1->InsertControl(Button1);
  }
}

/*
Note that it is 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;
}

Uses

Personal tools
Assistance