RAD Studio VCL Reference
|
Returns the number of child controls.
property ControlCount: Integer;
__property int ControlCount;
Read ControlCount when iterating over all the children of this control. The children of the control are listed in the Controls property array.
ControlCount is a read-only property.
C++ Examples:
/* This example uses an updown control and a group box on a form, with several controls contained within the group box. When the updown control or is clicked, the controls within the group box are moved in the appropriate direction. */ void __fastcall TForm1::UpDown1Click(TObject *Sender, TUDBtnType Button) { int I; TControl *ChildControl; for (I = 0; I < GroupBox1->ControlCount; I++) { ChildControl = GroupBox1->Controls[I]; if (Button == btNext) ChildControl->Top = ChildControl->Top + 15; else ChildControl->Top = ChildControl->Top - 15; } } void __fastcall TForm1::FormCreate(TObject *Sender) { const TColor colorarray[5] = {clYellow, clGreen, clBlue, clLime, clFuchsia}; GroupBox1->Brush->Color = clRed; for (int i = 0; i < GroupBox1->ControlCount; i++) dynamic_cast<TWinControl *>(GroupBox1->Controls[i])->Brush->Color = colorarray[i]; }
Delphi Examples:
{ This example uses an updown control and a group box on a form, with several controls contained within the group box. When the updown control is clicked, the controls within the group box are moved in the appropriate direction. } procedure TForm1.FormCreate(Sender: TObject); var I: Integer; const colorarray : Array[0..4] of TColor = (clYellow, clGreen, clBlue, clLime, clFuchsia); begin GroupBox1.Brush.Color := clRed; for I:= 0 to GroupBox1.ControlCount -1 do begin TWinControl(GroupBox1.Controls[I]).Brush.Color := colorarray[I]; end; end; procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType); var I: Integer; ChildControl: TControl; begin for I:= 0 to GroupBox1.ControlCount -1 do begin ChildControl := GroupBox1.Controls[I]; if Button = btNext then ChildControl.Top := ChildControl.Top + 15 else ChildControl.Top := ChildControl.Top - 15; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|