TControlParent (Delphi)

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

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (Button1.Parent <> GroupBox1) then // second click?
  begin
    RemoveControl(Button1);
    GroupBox1.InsertControl(Button1);
  end;
end;

{
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.

procedure TForm1.Button2Click(Sender: TObject);
begin
  Button2.Parent := GroupBox1;
end;

Uses

Personal tools
Assistance