diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index b2600a6..5b6f11d 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -391,6 +391,14 @@ { "source_path": "dotnet-desktop-guide/net/wpf/data/how-to-specify-the-direction-of-the-binding.md", "redirect_url": "/dotnet/desktop/wpf/data/binding-declarations-overview?view=netdesktop-5.0#binding-direction" + }, + { + "source_path": "dotnet-desktop-guide/net/winforms/controls/how-to-set-the-tab-order-on-windows-forms.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-tab-order?view=netdesktop-5.0" + }, + { + "source_path": "dotnet-desktop-guide/framework/winforms/controls/how-to-set-the-tab-order.md", + "redirect_url": "/dotnet/desktop/winforms/controls/how-to-set-the-tab-order-on-windows-forms?view=netframeworkdesktop-4.8" } ] } diff --git a/dotnet-desktop-guide/net/winforms/controls/how-to-add-a-picture-to-a-control.md b/dotnet-desktop-guide/net/winforms/controls/how-to-add-a-picture-to-a-control.md index 02ab1bb..12c7495 100644 --- a/dotnet-desktop-guide/net/winforms/controls/how-to-add-a-picture-to-a-control.md +++ b/dotnet-desktop-guide/net/winforms/controls/how-to-add-a-picture-to-a-control.md @@ -50,6 +50,6 @@ PictureBox1.Image = Image.FromFile _ ## See also -- -- -- +- +- +- diff --git a/dotnet-desktop-guide/net/winforms/controls/how-to-add-to-a-form.md b/dotnet-desktop-guide/net/winforms/controls/how-to-add-to-a-form.md index 0cb3031..3ece738 100644 --- a/dotnet-desktop-guide/net/winforms/controls/how-to-add-to-a-form.md +++ b/dotnet-desktop-guide/net/winforms/controls/how-to-add-to-a-form.md @@ -10,7 +10,7 @@ helpviewer_keywords: - "controls [Windows Forms], adding" --- -# Add a control (Windows Forms .NET) +# Add a control to a form (Windows Forms .NET) Most forms are designed by adding controls to the surface of the form to define a user interface (UI). A *control* is a component on a form used to display information or accept user input. @@ -46,8 +46,8 @@ The following code adds and positions two controls, a [Label](xref:System.Window ## See also -- [How to: Set the Text Displayed by a Windows Forms Control](how-to-set-the-display-text.md) -- [How to: Add an access key shortcut to a control](how-to-create-access-keys.md) -- -- -- +- [Set the Text Displayed by a Windows Forms Control](how-to-set-the-display-text.md) +- [Add an access key shortcut to a control](how-to-create-access-keys.md) +- +- +- diff --git a/dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys.md b/dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys.md index e26bc04..d649c63 100644 --- a/dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys.md +++ b/dotnet-desktop-guide/net/winforms/controls/how-to-create-access-keys.md @@ -86,6 +86,6 @@ button1.Text = "Print && Close"; ## See also -- [How to: Set the text displayed by a Windows Forms control](how-to-set-the-display-text.md) -- -- +- [Set the text displayed by a Windows Forms control](how-to-set-the-display-text.md) +- +- diff --git a/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-display-text.md b/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-display-text.md index 932e67c..c371641 100644 --- a/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-display-text.md +++ b/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-display-text.md @@ -76,5 +76,5 @@ You can also set the text by using the [designer](#designer). ## See also -- -- [How to: Create Access Keys for Windows Forms Controls](how-to-create-access-keys.md) +- [Create Access Keys for Windows Forms Controls](how-to-create-access-keys.md) +- diff --git a/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-tab-order.md b/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-tab-order.md new file mode 100644 index 0000000..d11652f --- /dev/null +++ b/dotnet-desktop-guide/net/winforms/controls/how-to-set-the-tab-order.md @@ -0,0 +1,102 @@ +--- +title: Set tab order of controls +description: 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. +ms.date: 05/24/2021 +dev_langs: + - "csharp" + - "vb" +helpviewer_keywords: + - "tab order [Windows Forms], controls on Windows forms" + - "Windows Forms controls, setting tab order" + - "controls [Windows Forms], setting tab order" + - "Windows Forms, setting tab order" +--- +# 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 property. + +You can also set the tab order by using the [designer](#designer). + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +Tab order can be set in the **Properties** window of the designer using the 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 control, treat their children as separate from the rest of the form. Each child in the container has its own 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 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. + +01. Select the control in the designer. + +01. 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."::: + + + +## Programmatic + +01. Set the `TabIndex` property to a numerical value. + + ```vb + Button1.TabIndex = 1 + ``` + + ```csharp + 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 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 property set to `true`, has its property automatically set to `true`. Other buttons in the radio button group have their `TabStop` property set to `false`. + +### Set TabStop programmatically + +01. Select the control in the designer. + +01. 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 TabStop in code + +01. Set the `TabStop` property to `false`. + + ```csharp + Button1.TabStop = false; + ``` + + ```vb + Button1.TabStop = False + ``` + +## See also + +- [Add a control to a form](how-to-add-to-a-form.md) +- +- diff --git a/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabindex.png b/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabindex.png new file mode 100644 index 0000000..8b21b9f Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabindex.png differ diff --git a/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabstop.png b/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabstop.png new file mode 100644 index 0000000..434f3b5 Binary files /dev/null and b/dotnet-desktop-guide/net/winforms/controls/media/how-to-set-the-tab-order/properties-tabstop.png differ diff --git a/dotnet-desktop-guide/net/winforms/controls/overview.md b/dotnet-desktop-guide/net/winforms/controls/overview.md index 926909d..1fe1595 100644 --- a/dotnet-desktop-guide/net/winforms/controls/overview.md +++ b/dotnet-desktop-guide/net/winforms/controls/overview.md @@ -37,5 +37,5 @@ For more information, see [Position and layout of controls](layout.md). ## See also - [Position and layout of controls](layout.md) -- [Label control overview (Windows Forms .NET)](labels.md) -- [Add a control (Windows Forms .NET)](how-to-add-to-a-form.md) +- [Label control overview](labels.md) +- [Add a control to a form](how-to-add-to-a-form.md) diff --git a/dotnet-desktop-guide/net/winforms/toc.yml b/dotnet-desktop-guide/net/winforms/toc.yml index 4a9b6f9..4565ba7 100644 --- a/dotnet-desktop-guide/net/winforms/toc.yml +++ b/dotnet-desktop-guide/net/winforms/toc.yml @@ -49,6 +49,8 @@ items: href: controls/how-to-create-access-keys.md - name: Set the text displayed by a control href: controls/how-to-set-the-display-text.md + - name: Set the the tab order of a control + href: controls/how-to-set-the-tab-order.md - name: Set the image displayed by a control href: controls/how-to-add-a-picture-to-a-control.md - name: User input - keyboard