# FocusControl(string)

> Move keyboard focus to a named control.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.IMGUIModule

```csharp
public static void FocusControl(string name)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name set using [GUI.SetNextControlName](/engine/6000.0/script-reference/unityengine/gui/setnextcontrolname.md).

### Remarks

Additional Resources: [GUI.SetNextControlName](/engine/6000.0/script-reference/unityengine/gui/setnextcontrolname.md), [GUI.GetNameOfFocusedControl](/engine/6000.0/script-reference/unityengine/gui/getnameoffocusedcontrol.md).

For focusing text in Editor GUI text fields, see [EditorGUI.FocusTextInControl](/engine/6000.0/script-reference/unityeditor/editorgui/focustextincontrol.md).

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    // When pressed the button, selects the "username" Textfield.
    public string username = "username";
    public string pwd = "a pwd";

    void OnGUI()
    {
        // Set the internal name of the textfield
        GUI.SetNextControlName("MyTextField");

        // Make the actual text field.
        username = GUI.TextField(new Rect(10, 10, 100, 20), username);
        pwd = GUI.TextField(new Rect(10, 40, 100, 20), pwd);

        // If the user presses this button, keyboard focus will move.
        if (GUI.Button(new Rect(10, 70, 80, 20), "Move Focus"))
            GUI.FocusControl("MyTextField");
    }
}
```
