UserForm.ChildControl Property

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the ChildControl property to obtain the form’s child control specified by its index. The total number of child controls on a form is specified by the ChildControlCount property.

In general, a control is a component that occupies a place on a form. For example, a button is a control, and a dialog is not. The ChildControl property only lets you access form controls, that is, it does not let you access components that do not occupy a place on a form, such as dialogs. To obtain a dialog component, use the Component property.

Declaration

UserForm.ChildControl(Index)

Read-Only Property A user form component object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the form’s child control. The index is zero-based: the first child control has index 0, the second - 1, and so on. The index of the last child control is ChildControlCount - 1.

Property Value

A form’s child control that has the specified index.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ChildControl property in square brackets: ChildControl[Index].

The ChildControl property is similar to the Component property. The difference in these properties is that ChildControl is used to access components that are situated directly on the form, whereas Component lets you access all form components -- those that are situated on the form as well as those that are situated on the form’s container components, such as panels and group boxes. Also, the ChildControl property lets you access all kinds of components except those that do not occupy a place on a form, such as dialogs, whereas the Component property can be used to enumerate all components, including dialogs.

You can also obtain the form component by its name:

Example

The following code obtains the form’s control by its index, sets the control’s properties and shows the form:

JavaScript, JScript

function Test()
{
  var Control, TestForm;

  // Obtains the form
  TestForm = UserForms.FormByName("TestForm");

  // Obtains the form’s child control by its index
  Control = TestForm.ChildControl(0);
  // Modifies the control’s properties
  Control.Enabled = false;
  Control.Caption = "OK";
  // Displays the form
  TestForm.ShowModal();

  …
}

Python

def Test():
  # Obtains the form
  TestForm = UserForms.FormByName["TestForm"]
  # Obtains the form's child control by its index
  Control = TestForm.ChildControl[0]
  # Modifies the control's properties
  Control.Enabled = False
  Control.Caption = "OK"
  # Displays the form
  TestForm.ShowModal()
  # ...

VBScript

Sub Test

  Dim Control, TestForm

  ' Obtains the form
  Set TestForm = UserForms.FormByName("TestForm")

  ' Obtains the form’s child control by its index
  Set Control = TestForm.ChildControl(0)
  ' Modifies the control’s properties
  Control.Enabled = False
  Control.Caption = "OK"
  ' Displays the form
  TestForm.ShowModal

  …
End Sub

DelphiScript

procedure Test();
var Control, TestForm;

begin
  // Obtains the form
  TestForm := UserForms.FormByName('TestForm');

  // Obtains the form’s child control by its index
  Control := TestForm.ChildControl[0];
  // Modifies the control’s properties
  Control.Enabled := false;
  Control.Caption := 'OK';
  // Displays the form
  TestForm.ShowModal;

  …
end;

C++Script, C#Script

function Test()
{
  var Control, TestForm;

  // Obtains the form
  TestForm = UserForms["FormByName"]("TestForm");

  // Obtains the form’s child control by its index
  Control = TestForm["ChildControl"](0);
  // Modifies the control’s properties
  Control["Enabled"] = false;
  Control["Caption"] = "OK";
  // Displays the form
  TestForm["ShowModal"]();

  …
}

See Also

ChildControlByName Property
ChildControlCount Property
Component Property
ComponentByName Property
ComponentCount Property

Highlight search results