UserForm.Visible Property

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

Description

The Visible property lets you determine or set whether the form is visible on screen.

To display the form on screen, set the Visible property to True or use the Show or ShowModal method. To hide the form, set Visible to False or use the Hide method.

Declaration

UserForm.Visible

Read-Write Property Boolean

Applies To

The property is applied to the following object:

Property Value

True if the form is visible. False otherwise.

Example

The following example shows the main user form in modal mode, and then, as a user clicks a button on that form, toggles the visibility of the additional user form. The example assumes that the current project contains two user forms. One form is named TestForm, and the other - OptionsForm. TestForm contains a button.

JavaScript, JScript

// Shows the main user form
function Main()
{
  var TestForm;
  …
  // Obtains the user form by its name
  TestForm = UserForms.FormByName("TestForm");
  // Shows the form
  TestForm.ShowModal();
  …

}

// Shows or hides the additional user form upon a button click
function TestForm_btn_toggleForm_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form
  OptionsForm = UserForms.FormByName("OptionsForm");

  // Checks if the user form is visible or not and switches its state
  if (OptionsForm.Visible)
    OptionsForm.Visible = false
  else
    OptionsForm.Visible = true;
}

Python

# Shows the main user form 
def Main():
  # ...
  # Obtains the user form by its name 
  TestForm = UserForms.FormByName["TestForm"]
  # Shows the form 
  TestForm.ShowModal()
  # ...
  
# Shows or hides the additional user form upon a button click 
def TestForm_btn_toggleForm_OnClick(Sender):
  # Obtains the user form 
  OptionsForm = UserForms.FormByName["OptionsForm"]
  # Checks if the user form is visible or not and switches its state 
  if OptionsForm.Visible:
    OptionsForm.Visible = False
  else:
    OptionsForm.Visible = True

VBScript

' Shows 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

' Shows or hides the additional user form upon a button click
Sub TestForm_btn_toggleForm_OnClick(Sender)

  Dim OptionsForm
  ' Obtains the user form
  Set OptionsForm = UserForms.FormByName("OptionsForm")

  ' Checks if the user form is visible or not and switches its state
  If OptionsForm.Visible Then
    OptionsForm.Visible = False
  Else
    OptionsForm.Visible = True
  End If
End Sub

DelphiScript

// Shows 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;

// Shows or hides the additional user form upon a button click
procedure TestForm_btn_toggleForm_OnClick(Sender);
  var OptionsForm;
begin
  // Obtains the user form
  OptionsForm := UserForms.FormByName('OptionsForm');

  // Checks if the user form is visible or not and switches its state
  if OptionsForm.Visible then
    OptionsForm.Visible := false
  else
    OptionsForm.Visible := true;
end;

C++Script, C#Script

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

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


}

// Shows or hides the additional user form upon a button click
function TestForm_btn_toggleForm_OnClick(Sender)
{
  var OptionsForm;
  // Obtains the user form
  OptionsForm = UserForms["FormByName"]("OptionsForm");

  // Checks if the user form is visible or not and switches its state
  if (OptionsForm["Visible"])
    OptionsForm["Visible"] = false
  else
    OptionsForm["Visible"] = true;
}

See Also

Hide Method
Show Method
ShowModal Method
OnHide Event
OnShow Event

Highlight search results