SetFocus Method

Assigns the focus to a control.

Control.SetFocus

Remarks

Applies To: CheckBox | Column | ComboBox | CommandButton | Container Object | Control Object | EditBox | Grid | ListBox | OLE Bound Control | OLE Container Control | OptionButton | Page Object | Spinner | TextBox

You cannot assign the focus to a control if the control's Enabled or Visible property is set to false (.F.), or the control's When event returns false (.F.). If the Enabled or Visible property has been set to false (.F.), you must first set it to true (.T.) before the control can receive the focus from the SetFocus method.

Once a control has the focus, any user input is directed to that control.

In Visual FoxPro 9.0, the SetFocus method is not supported in the When Event, Valid Event, RangeHigh Event and RangeLow Event events. However, you can include a RETURN Command with an object name (RETURN <ObjectName>) in these events to set the focus to another control. If a RETURN command with an object name is included, the focus is set to the control specified with <ObjectName>.

The object specified in the RETURN command must be a valid Visual FoxPro object that can receive the focus. If the object you specify is disabled or cannot receive the focus, the next object in the tab order receives the focus. Focus remains with the current object if you specify an invalid object.

RETURN <ObjectName> allows you to set the focus to an object on another visible form. You can also set the focus to an object on a non-visible page of a pageframe, but you must include code to activate that page (for example, PageFrame1.ActivePage = 2).

See Also

Reference

Enabled Property (Visual FoxPro)
GotFocus Event
LostFocus Event
Visible Property (Visual FoxPro)

Other Resources

Methods (Visual FoxPro)
Language Reference (Visual FoxPro)