UserForm.Show Method

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The Show method sets the form’s Visible property to True and thus displays the form on screen. If the form is displayed using the Show method, the script execution continues after the form appears on the screen.

The form is displayed until the Visible property is set to False, or the Hide method is called, or the script execution ends.

To display the form as a modal dialog, use the ShowModal method. To hide the form, use the Hide method or set the Visible property to False.

Declaration

UserForm.Show()

Result None

Applies To

The method is applied to the following object:

Result Value

None.

Remarks

When the form is displayed for the first time, by default it appears in the center of the screen. If you need to display the form in the custom screen position, specify the desired X and Y coordinates in the Left and Top properties respectively, before calling the Show method.

Example

The following example shows one form in modal mode, and then, as a user clicks buttons on that form, an additional user form is displayed or hidden. The example assumes that the current project contains two user forms named TestForm and OptionsForm, and TestForm contains two buttons.

JavaScript, JScript

// Displays the main user form
function Main()
{
  var TestForm;

  …
  // Obtains the user form by its name
  TestForm = UserForms.FormByName("TestForm");
  // Shows the form
  TestForm.ShowModal()
  …
}

// Displays the additional user form
function TestForm_btn_ShowOptions_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form by its name
  OptionsForm = UserForms.FormByName("OptionsForm");
  // Sets the user form width, height, position on screen and caption
  OptionsForm.Top = 120;
  OptionsForm.Left = 420;
  OptionsForm.Width = 470;
  OptionsForm.Height = 350;
  OptionsForm.Caption = "Options";
  // Shows the user form
  OptionsForm.Show();

}

// Hides the additional user form
function TestForm_btn_HideOptions_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form by its name
  OptionsForm = UserForms.FormByName("OptionsForm");
  // Hides the user form
  OptionsForm.Hide();
}

Python

# Displays the main user form 
def Main():
  # ...
  # Obtains the user form by its name
  TestForm = UserForms.FormByName["TestForm"] 
  # Shows the form
  TestForm.ShowModal()
  # ...

# Displays the additional user form
def TestForm_btn_ShowOptions_OnClick(Sender):
  # Obtains the user form by its name
  OptionsForm = UserForms.FormByName["OptionsForm"]
  # Sets the user form width, height, position on screen and caption
  OptionsForm.Top = 120
  OptionsForm.Left = 420
  OptionsForm.Width = 470
  OptionsForm.Height = 350
  OptionsForm.Caption = "Options"
  # Shows the user form
  OptionsForm.Show()
  
# Hides the additional user form
def TestForm_btn_HideOptions_OnClick(Sender):
  # Obtains the user form by its name
  OptionsForm = UserForms.FormByName("OptionsForm")
  # Hides the user form
  OptionsForm.Hide()

VBScript

' Displays the main user form
Sub Main

  Dim TestForm

  …
  ' Obtains the user form by its name
  Set TestForm = UserForms.FormByName("TestForm")
  ' Shows the form
  TestForm.ShowModal
  …
End Sub

' Displays the additional user form
Sub TestForm_btn_ShowOptions_OnClick(Sender)

  Dim OptionsForm
  ' Obtains the user form by its name
  Set OptionsForm = UserForms.FormByName("OptionsForm")
  ' Sets the user form width, height, position on screen and caption
  OptionsForm.Top = 120
  OptionsForm.Left = 420
  OptionsForm.Width = 470
  OptionsForm.Height = 350
  OptionsForm.Caption = "Options"
  ' Shows the user form
  OptionsForm.Show

End Sub

' Hides the additional user form
Sub TestForm_btn_HideOptions_OnClick(Sender)

  Dim OptionsForm
  ' Obtains the user form by its name
  Set OptionsForm = UserForms.FormByName("OptionsForm")
  ' Hides the user form
  OptionsForm.Hide

End Sub

DelphiScript

// Displays the main user form
procedure Main();
var TestForm;

begin
  …
  // Obtains the user form by its name
  TestForm := UserForms.FormByName('TestForm');
  // Shows the form
  TestForm.ShowModal;
  …
end;

// Displays the additional user form
procedure TestForm_btn_ShowOptions_OnClick(Sender);
var OptionsForm;
begin
  // Obtains the user form by its name
  OptionsForm := UserForms.FormByName('OptionsForm');
  // Sets the user form width, height, position on screen and caption
  OptionsForm.Top := 120;
  OptionsForm.Left := 420;
  OptionsForm.Width := 470;
  OptionsForm.Height := 350;
  OptionsForm.Caption := 'Options';
  // Shows the user form
  OptionsForm.Show;

end;

// Hides the additional user form
procedure TestForm_btn_HideOptions_OnClick(Sender);
var OptionsForm;
begin
  // Obtains the user form by its name
  OptionsForm := UserForms.FormByName('OptionsForm');
  // Hides the user form
  OptionsForm.Hide;
end;

C++Script, C#Script

// Displays the main user form
function Main()
{
  var TestForm;

  …
  // Obtains the user form by its name
  TestForm = UserForms["FormByName"]("TestForm");
  // Shows the form
  TestForm["ShowModal"]()
  …
}

// Displays the additional user form
function TestForm_btn_ShowOptions_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form by its name
  OptionsForm = UserForms["FormByName"]("OptionsForm");
  // Sets the user form width, height, position on screen and caption
  OptionsForm["Top"] = 120;
  OptionsForm["Left"] = 420;
  OptionsForm["Width"] = 470;
  OptionsForm["Height"] = 350;
  OptionsForm["Caption"] = "Options";
  // Shows the user form
  OptionsForm["Show"]();

}

// Hides the additional user form
function TestForm_btn_HideOptions_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form by its name
  OptionsForm = UserForms["FormByName"]("OptionsForm");
  // Hides the user form
  OptionsForm["Hide"]();
}

See Also

Working With User Forms in Tests
UserForm.Hide Method
UserForm.ShowModal Method
UserForm.Visible Property
UserForm.OnShow Event

Highlight search results