UserForm.OnShow Event

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

The OnShow event occurs when the user form appears on screen. This happens when the form’s Show or ShowModal method is called, or when the Visible property is set to True.

You can create an event handler for the OnShow event to perform certain actions when the form is displayed. For example, you can populate the list of items in form components such as combo boxes and list boxes, set the components’ initial values, and so on.

Declaration

OnShow(Sender)

Sender [in]    Required    A UserForm object    
Result None

Applies To

The property is applied to the following object:

Parameters

The event has the following parameter:

Sender

A UserForm object that raised the event.

Result Value

None.

Remarks

For information on how to create handlers for events of user forms and form components, see Handling Events in User Forms.

Example

The following code snippet demonstrates how you can set the item initially selected in a TcxListBox component from the form’s OnShow event handler:

JavaScript, JScript

function UserForm1_OnShow(Sender)
{
  // Select the third item in the cxListBox1 control
  UserForms.UserForm1.cxListBox1.ItemIndex = 2
}

Python

def UserForm1_OnShow(Sender):
  # Select the third item in the cxListBox1 control
  UserForms.UserForm1.cxListBox1.ItemIndex = 2

VBScript

Sub UserForm1_OnShow(Sender)
  ' Select the third item in the cxListBox1 control
  UserForms.UserForm1.cxListBox1.ItemIndex = 2
End Sub

DelphiScript

procedure UserForm1_OnShow(Sender);
begin
  // Select the third item in the cxListBox1 control
  UserForms.UserForm1.cxListBox1.ItemIndex := 2;
end;

C++Script, C#Script

function UserForm1_OnShow(Sender)
{
  // Select the third item in the cxListBox1 control
  UserForms["UserForm1"]["cxListBox1"]["ItemIndex"] = 2
}

See Also

Handling Events in User Forms
OnHide Event
Show Method
ShowModal Method

Highlight search results