Edit

Share via


How to set the tab order on Windows Forms

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 directly by using the designer's Property window or with Tab Order mode.

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 focuses 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 on your form can be skipped in the tab order by setting the TabStop property false.

Designer

Use the Visual Studio 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

The tab order of controls can be set through code:

  1. Set the TabIndex property to a numerical value.

    Button1.TabIndex = 1
    
    Button1.TabIndex = 1;
    

Use Tab Order mode

Visual Studio's Visual Designer provides an interactive way to set the TabIndex property for controls. The Tab Order mode allows you to sequentially set the tab order of controls by clicking on them in the Visual Designer.

  1. In Visual Studio, on the View menu, select Tab Order.

    This activates the tab-order selection mode on the form. A number (representing the TabIndex property) appears in the upper-left corner of each control.

  2. Click the controls sequentially to establish the tab order you want.

    Note

    A control's place within the tab order can be set to any value greater than or equal to 0. When duplicates occur, the z-order of the two controls is evaluated and the control on top is tabbed to first. (The z-order is the visual layering of controls on a form along the form's z-axis [depth]. The z-order determines which controls are in front of other controls.) For more information on z-order, see Layering Objects on Windows Forms.

  3. To finish, select View > Tab Order again.

    Note

    Controls that can't be focused, such as disabled and invisible controls, aren't included in the tab order. As a user presses the Tab key, these controls are skipped.

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