SetFocus Method (AForm)

Moves the focus to the object.

Syntax

Object.SetFocus()

The SetFocus method syntax has the following parts:

 

Name

Type

Description

Object

AForm

AForm object

Comments

The object must be a Form object, MDIForm object, or control that can receive the focus. After invoking the SetFocus method, any user input is directed to the specified form or control.

The focus can only be moved to a visible form or control. Because a form and controls on a form are not visible until the form's Load event has finished, you can't use the SetFocus method to move the focus to the form being loaded in its own OnLoad event unless you first use the Show method to show the form before the Form_OnLoad event procedure is finished.

The focus also cannot be moved to a form or control if the Enabled property is set to False. If the Enabled property has been set to False at design time, it must first be set to True before it can receive the focus using the SetFocus method.

Example

The following statement changes the AForm so it has the focus:

afrm1.SetFocus()

Applies to

AForm

See Also

Enabled, MDIActiveForm, OnGotFocus, OnLoad, OnLostFocus