Udostępnij za pośrednictwem


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.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To set the tab order of a control

  1. On the View menu, click 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. When you have finished, click Tab Order on the View menu again to leave tab order mode.

    Note

    Controls that cannot get the focus, as well as disabled and invisible controls, do not have a TabIndex property and are not included in the tab order. As a user presses the TAB key, these controls are skipped.

Alternatively, tab order can be set in the Properties window using the TabIndex property. The TabIndex property of a control determines where it is positioned in the tab order. By default, the first control drawn has a TabIndex value of 0, the second has a TabIndex of 1, and so on.

Additionally, by default, a GroupBox control has its own TabIndex value, which is a whole number. A GroupBox control itself cannot have focus at run time. Thus, each control within a GroupBox has its own decimal TabIndex value, beginning with .0. Naturally, as the TabIndex of a GroupBox control is incremented, the controls within it will be incremented accordingly. If you changed a TabIndex value from 5 to 6, the TabIndex value of the first control in its group automatically changes to 6.0, and so on.

Finally, 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, you can make a control be passed over in the tab order of the form.

To remove a control from the tab order

  • Set the control's TabStop property to false in the Properties window.

    A control whose TabStop property has been set to false still maintains its position in the tab order, even though the control is skipped when you cycle through the controls with the TAB key.

    Note

    A radio button group has a single tab stop at run time. The selected button (that is, the button with its Checked property set to true) has its TabStop property automatically set to true, while the other buttons have their TabStop property set to false. For more information about grouping RadioButton controls, see Grouping Windows Forms RadioButton Controls to Function as a Set.

See Also

Reference

Windows Forms Controls by Function

Other Resources

Windows Forms Controls

Arranging Controls on Windows Forms

Controls to Use on Windows Forms