RAD Studio VCL Reference
|
Indicates the parent of the control.
property Parent: TWinControl;
__property TWinControl * Parent;
Use the Parent property to get or set the parent of this control. The parent of a control is the control that contains the control. For example, if an application includes three radio buttons in a group box, the group box is the parent of the three radio buttons, and the radio buttons are the child controls of the group box.
To serve as a parent, a control must be an instance of a descendant of TWinControl.
When creating a new control at runtime, assign a Parent property value for the new control. Usually, this is a form, panel, group box, or some control that is designed to contain another. Changing the parent of a control moves the control onscreen so that it is displayed within the new parent. When the parent control moves, the child moves with the parent.
Some controls (such as ActiveX controls) are contained in native windows rather than in a parent VCL control. For these controls, the value of Parent is nil (Delphi) or NULL (C++) and the ParentWindow property specifies the window.
C++ Examples:
/* 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; }
Delphi Examples:
{ 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. } 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;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|