From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!


New in 2021r3

Supported for all project types and targets.

If applicable, sets the focus to the DesktopUIControl. KeyDown events are directed to the control.


If the control cannot get the focus on the platform on which the application is running, SetFocus does nothing. The SetFocus method of the DesktopWindow class or the ClearFocus method can be used to remove the focus from the control that currently has the focus, leaving no control with the focus.

On the Mac you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.

Sample Code

The following example in the Opening event sets the focus to the that control. If another control has the focus when this line is executed, then the user sees this control gets the focus.