UserForm.SetFocus Method

Applies to TestComplete 14.93, last modified on September 27, 2021

Description

Use the SetFocus method to set the input focus to the user form to which UserFormObj corresponds. If the user form cannot obtain the input focus, the method fails and posts an error message to the test log.

Declaration

UserForm.SetFocus()

Result None

Applies To

The method is applied to the following object:

Result Value

None.

Example

The following example shows the user form and sets the focus to it:

JavaScript, JScript

function Test()
{
  var TestForm;
  // Obtains the user form
  TestForm = UserForms.TestForm
  // Displays the user form
  TestForm.Show()
  …
  // Sets the focus to the user form
  TestForm.SetFocus()
  …
}

Python

def Test():
  # Obtains the user form
  TestForm = UserForms.TestForm
  #  Displays the user form
  TestForm.Show()
  # ...
  # Sets the focus to the user form
  TestForm.SetFocus()
  # ...

VBScript

Sub Test
  Dim TestForm
  ' Obtains the user form
  Set TestForm = UserForms.TestForm
  ' Displays the user form
  TestForm.Show
  …
  ' Sets the focus to the user form
  TestForm.SetFocus
  …
End Sub

DelphiScript

procedure Test();
var TestForm;
begin
  // Obtains the user form
  TestForm := UserForms.TestForm;
  // Displays the user form
  TestForm.Show;
  …
  // Sets the focus to the user form
  TestForm.SetFocus;
  …
end;

C++Script, C#Script

function Test()
{
  var TestForm;
  // Obtains the user form
  TestForm = UserForms["TestForm"]
  // Displays the user form
  TestForm["Show"]()
  …
  // Sets the focus to the user form
  TestForm["SetFocus"]()
  …
}

See Also

Working With User Forms in Tests

Highlight search results