Focus Method
Collapse the table of content
Expand the table of content

Control.Focus Method

Sets input focus to the control.

[Visual Basic]
Public Function Focus() As Boolean
public bool Focus();
public: bool Focus();
public function Focus() : Boolean;

Return Value

true if the input focus request was successful; otherwise, false.


The Focus method returns true if the control successfully received input focus. The control can have the input focus while not displaying any visual cues of having the focus. This behavior is primarily observed by the nonselectable controls listed below, or any controls derived from them.

A control can be selected and receive input focus if all the following are true: its ControlStyles.Selectable style bit is set to true, it is contained in another control, and all its parent controls are both visible and enabled.

The Windows Forms controls in the following list are not selectable. Controls derived from these controls are also not selectable.


[Visual Basic, C#, C++] The following example sets focus to the specified Control, if it can receive focus.

[Visual Basic] 
Public Sub ControlSetFocus(control As Control)
   ' Set focus to the control, if it can receive focus.
   If control.CanFocus Then
   End If
End Sub

public void ControlSetFocus(Control control)
   // Set focus to the control, if it can receive focus.

   void ControlSetFocus(Control* control) {
      // Set focus to the control, if it can receive focus.
      if (control->CanFocus) {

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

.NET Framework Security: 

See Also

Control Class | Control Members | System.Windows.Forms Namespace | CanFocus | ContainsFocus | Focused | CanSelect

© 2016 Microsoft