Home > Language Reference > Classes > Form

Focus Property

Control having the focus.

Syntax

Public Property Get Focus() As Control
Public Property Set Focus(ByRef
objFocus As Control)

ParameterDescription
objFocusControl that should receive the focus.

Remarks

The Focus property returns or changes the control which has the focus, in other words the control that receives characters that are entered (including 5-way navigator events). On recent devices supporting the one-handed navigation feature, most controls can gain the focus. On older devices, only Field controls can be focused. If you try to set the focus to a control that cannot be focused, it is simply set to Nothing and no error occurs.

The following example shows how to set the focus to a field when the form is opened, and how to implement a Paste command:

Private Sub Form_Load()
  Set Focus = Field1
End Sub

Private Sub mnuPaste_Click()
  Dim c as Control

  Set c = Focus
  If Not c Is Nothing And c.Implements(TypeID(Field)) Then Field(c).Paste
End Sub

It is possible to set the value Nothing to this property. In this case, no control has the focus, the blinking cursor disappears and only the active form continues to receive the characters entered.

A control whose Visible property is set to False cannot gain the focus. If you try to set the focus to a hidden control, it is instead set to Nothing. The same happens if a focused control becomes invisible.

If the devices supports the blue focus ring feature, setting the focus to a control by affecting a new value to this property also moves the blue ring to that control.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0-
Windows CEWindows CE 3.0-