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.
To set the tab order of a control
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.
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.
When you have finished, select 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
.NET Desktop feedback