title | description | ms.date | dev_langs | helpviewer_keywords | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Set tab order of controls |
Learn how to set the tab order of controls on your Windows Forms for .NET. Set the tab order with Visual Studio or using the TabIndex property in the Properties window. |
05/24/2021 |
|
|
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 xref:System.Windows.Forms.Control.TabIndex%2A 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 xref:System.Windows.Forms.Control.TabIndex%2A 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 xref:System.Windows.Forms.GroupBox control, treat their children as separate from the rest of the form. Each child in the container has its own xref:System.Windows.Forms.Control.TabIndex%2A 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 xref:System.Windows.Forms.Control.TabStop%2A property, a control is passed over in the tab order of the form.
Use the Visual Studio designer Properties window to set the tab order of a control.
-
Select the control in the designer.
-
In the Properties window in Visual Studio, set the TabIndex property of the control to an appropriate number.
:::image type="content" source="media/how-to-set-the-tab-order/properties-tabindex.png" alt-text="Visual Studio Properties pane for .NET Windows Forms with TabIndex property shown.":::
-
Set the
TabIndex
property to a numerical value.Button1.TabIndex = 1
Button1.TabIndex = 1;
You can prevent a control from receiving focus when the Tab key is pressed, by setting the xref:System.Windows.Forms.Control.TabStop%2A 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 xref:System.Windows.Forms.RadioButton.Checked%2A property set to true
, has its xref:System.Windows.Forms.Control.TabStop%2A property automatically set to true
. Other buttons in the radio button group have their TabStop
property set to false
.
-
Select the control in the designer.
-
In the Properties window in Visual Studio, set the TabStop property to
False
.:::image type="content" source="media/how-to-set-the-tab-order/properties-tabstop.png" alt-text="Visual Studio Properties pane for .NET Windows Forms with TabStop property shown.":::
-
Set the
TabStop
property tofalse
.Button1.TabStop = false;
Button1.TabStop = False
- Add a control to a form
- xref:System.Windows.Forms.Control.TabIndex%2A?displayProperty=fullName
- xref:System.Windows.Forms.Control.TabStop%2A?displayProperty=fullName