UserForm.Top Property

Applies to TestComplete 15.40, last modified on March 25, 2022

Description

Use the Top property to obtain or set the vertical coordinate of the form’s top edge, relative to the screen. The default value of the Top property is such that the form is centered on the screen vertically when it is displayed for the first time. This value is equal to:

JavaScript, JScript

aqConvert.VarToInt((Sys.Desktop.Height - UserFormObj.Height)/2);

Python

aqConvert.VarToInt((Sys.Desktop.Height - UserFormObj.Height)/2)

VBScript

aqConvert.VarToInt((Sys.Desktop.Height - UserFormObj.Height)/2)

DelphiScript

aqConvert.VarToInt((Sys.Desktop.Height - UserFormObj.Height)/2);

C++Script, C#Script

aqConvert["VarToInt"]((Sys["Desktop"]["Height"] - UserFormObj["Height"])/2);

If you need the form to appear in the custom position on the screen, use the Left property to specify the desired horizontal coordinate, and the Top property to specify the vertical coordinate.

Declaration

UserForm.Top

Read-Write Property Integer

Applies To

The property is applied to the following object:

Property Value

An integer value that specifies the vertical position of the form’s top edge, in pixels.

Example

The following code snippet sets the form’s caption, size and initial position on the screen, displays the form and checks which form button the user has pressed to close the form.

JavaScript, JScript

function FormTest()
{

  var TestForm, mr;
  // Obtains the user form
  TestForm = UserForms.FormByName("TestForm");

  // Sets the form’s caption
  TestForm.Caption = "Press any button";
  // Sets the coordinates of the form’s top edge
  TestForm.Left = 500;
  TestForm.Top = 500;

  // Sets the form’s size
  TestForm.Width = 214;
  TestForm.Height = 100;

  // Displays the form and checks what button the user has pressed
  mr = TestForm.ShowModal();
  if (mr == mrOK)
    ShowMessage("The OK button was pressed");
  else
    ShowMessage("The Cancel button was pressed");

}

Python

def FormTest():
  # Obtains the user form
  TestForm = UserForms.FormByName["TestForm"]
  # Sets the form's caption
  TestForm.Caption = "Press any button"
  # Sets the coordinates of the form's top edge
  TestForm.Left = 500
  TestForm.Top = 500
  # Sets the form's size
  TestForm.Width = 214
  TestForm.Height = 100
  # Displays the form and checks what button the user has pressed
  mr = TestForm.ShowModal()
  if mr == mrOK:
    ShowMessage("The OK button was pressed")
  else:
    ShowMessage("The Cancel button was pressed")

VBScript

Sub FormTest

  Dim TestForm, mr

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

  ' Sets the form’s caption
  TestForm.Caption = "Press any button"
  ' Sets the coordinates of the form’s top edge
  TestForm.Left = 500
  TestForm.Top = 500

  ' Sets the form’s size
  TestForm.Width = 214
  TestForm.Height = 100

  ' Displays the form and checks what button the user has pressed
  mr = TestForm.ShowModal
  If mr = mrOK Then
    ShowMessage "The OK button was pressed"
  Else
    ShowMessage "The Cancel button was pressed"
  End If

End Sub

DelphiScript

procedure FormTest();
var TestForm, mr;
begin

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

  // Sets the form’s caption
  TestForm.Caption := 'Press any button';
  // Sets the coordinates of the form’s top edge
  TestForm.Left := 500;
  TestForm.Top := 500;

  // Sets the form’s size
  TestForm.Width := 214;
  TestForm.Height := 100;

  // Displays the form and checks what button the user has pressed
  mr := TestForm.ShowModal;
  if mr = mrOK then
    ShowMessage('The OK button was pressed')
  else
    ShowMessage('The Cancel button was pressed');

end;

C++Script, C#Script

function FormTest()
{

  var TestForm, mr;
  // Obtains the user form
  TestForm = UserForms["FormByName"]("TestForm");

  // Sets the form’s caption
  TestForm["Caption"] = "Press any button";
  // Sets the coordinates of the form’s top edge
  TestForm["Left"] = 500;
  TestForm["Top"] = 500;

  // Sets the form’s size
  TestForm["Width"] = 214;
  TestForm["Height"] = 100;

  // Displays the form and checks what button the user has pressed
  mr = TestForm["ShowModal"]();
  if (mr == mrOK)
    ShowMessage("The OK button was pressed");
  else
    ShowMessage("The Cancel button was pressed");

}

See Also

Height Property
Left Property
Width Property

Highlight search results