UserForm Object

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

The UserForm object provides scripting access to each user form contained in the current TestComplete project. To obtain the UserForm object in scripts, use the UserForms.Form or UserForms.FormByName methods, or use the following statement:

JavaScript, JScript

var form = UserForms.form_name;

Python

form = UserForms.form_name

VBScript

Set form = UserForms.form_name

DelphiScript

var form : OleVariant;
...
form := UserForms.form_name;

C++Script, C#Script

var form = UserForms.form_name;

Above form_name is the unique name of the desired form.

The UserForm object contains properties that let you specify the text displayed in the form’s title bar, get or set the position of the form on the screen and iterate through form's components. Using methods of the UserForm object, you can display or hide the form on the screen.

Besides the properties and methods listed below for each form component, (no matter if it is situated directly on the form or on the container component such as panel or group box) the UserForm object provides a property with the same name that returns the program object providing access to that component, its properties and methods.

For more information on how to work with user forms and their components in scripts, see Working With User Forms in Tests.

Members

Example

The following routine uses properties of the UserForm object to set the form caption and position on the screen, displays the form and then checks which form button the user pressed to close the form.

JavaScript, JScript

function Test ()
{
  var form, mr;
  form = UserForms.TestForm;
  form.Left = 100;
  form.Top = 100;
  form.Caption = "Press any button...";
  mr = form.ShowModal();
  switch (mr)
  {
    case mrOK: ShowMessage ("The OK button was pressed."); break;
    case mrCancel: ShowMessage ("The Cancel button was pressed."); break;
    default: ShowMessage ("Another button was pressed.");
  }
}

Python

def Test():
  form = UserForms.TestForm
  form.Left = 100
  form.Top = 100
  form.Caption = "Press any button..."
  mr = form.ShowModal()
  if mr == mrOK:
    ShowMessage("The OK button was pressed.")
  elif mr == mrCancel:
    ShowMessage("The Cancel button was pressed.")
  else: 
    ShowMessage("Another button was pressed.")

VBScript

Sub Test
  Set form = UserForms.TestForm
  form.Left = 100
  form.Top = 100
  form.Caption = "Press any button..."
  mr = form.ShowModal
  Select Case mr
    Case mrOK ShowMessage ("The OK button was pressed.")
    Case mrCancel ShowMessage ("The Cancel button was pressed.")
    Case Else ShowMessage ("Another button was pressed.")
  End Select
End Sub

DelphiScript

procedure Test;
var form, mr : OleVariant;
begin
  form := UserForms.TestForm;
  form.Left := 100;
  form.Top := 100;
  form.Caption := 'Press any button...';
  mr := form.ShowModal;
  case mr of
    mrOK: ShowMessage ('The OK button was pressed.');
    mrCancel: ShowMessage ('The Cancel button was pressed.');
  else
    ShowMessage ('Another button was pressed.');
  end;
end;

C++Script, C#Script

function Test ()
{
  var form, mr;
  form = UserForms["TestForm"];
  form["Left"] = 100;
  form["Top"] = 100;
  form["Caption"] = "Press any button...";
  mr = form["ShowModal"]();
  switch (mr)
  {
    case mrOK: ShowMessage ("The OK button was pressed."); break;
    case mrCancel: ShowMessage ("The Cancel button was pressed."); break;
    default: ShowMessage ("Another button was pressed.");
  }
}

See Also

User Forms
Working With User Forms in Tests
UserForms Object

Highlight search results