Edit

Share via


How to set the tab order on Windows Forms (Windows Forms .NET)

The tab order is the order in which a user moves focus from one control to another by pressing the Tab key. Each form has its own tab order. By default, the tab order is the same as the order in which you created the controls. Tab-order numbering begins with zero and ascends in value, and is set with the TabIndex property.

You can also set the tab order by using the designer.

Tab order can be set in the Properties window of the designer using the TabIndex property. The TabIndex property of a control determines where it's positioned in the tab order. By default, the first control added to the designer has a TabIndex value of 0, the second has a TabIndex of 1, and so on. Once the highest TabIndex has been focused, pressing Tab will cycle and focus the control with the lowest TabIndex value.

Container controls, such as a GroupBox control, treat their children as separate from the rest of the form. Each child in the container has its own TabIndex value. Because a container control can't be focused, when the tab order reaches the container control, the child control of the container with the lowest TabIndex is focused. As the Tab is pressed, each child control is focused according to its TabIndex value until the last control. When Tab is pressed on the last control, focus resumes to the next control in the parent of the container, based on the next TabIndex value.

Any control of the many on your form can be skipped in the tab order. Usually, pressing Tab successively at run time selects each control in the tab order. By turning off the TabStop property, a control is passed over in the tab order of the form.

Designer

Use the Visual Studio designer Properties window to set the tab order of a control.

  1. Select the control in the designer.

  2. In the Properties window in Visual Studio, set the TabIndex property of the control to an appropriate number.

    Visual Studio Properties pane for .NET Windows Forms with TabIndex property shown.

Programmatic

  1. Set the TabIndex property to a numerical value.

    Button1.TabIndex = 1
    
    Button1.TabIndex = 1;
    

Remove a control from the tab order

You can prevent a control from receiving focus when the Tab key is pressed, by setting the TabStop property to false. The control is skipped when you cycle through the controls with the Tab key. The control doesn't lose its tab order when this property is set to false.

Note

A radio button group has a single tab stop at run-time. The selected button, the button with its Checked property set to true, has its TabStop property automatically set to true. Other buttons in the radio button group have their TabStop property set to false.

Set TabStop with the designer

  1. Select the control in the designer.

  2. In the Properties window in Visual Studio, set the TabStop property to False.

    Visual Studio Properties pane for .NET Windows Forms with TabStop property shown.

Set TabStop programmatically

  1. Set the TabStop property to false.

    Button1.TabStop = false;
    
    Button1.TabStop = False
    

See also