Visually Setting a Form's Tab Order
A Windows-based application is usually operated using mouse movements and clicks. However, all forms should provide support for users who prefer to use the keyboard. A key part of this is ensuring that the tab order feels natural and is easy to use.
The TabIndex Property
All of the interactive controls on a Windows form include a TabIndex property; the property holds an integer value. When the form is displayed at run-time, the focus is initially set to the control with the lowest TabIndex value. If the user presses the tab key on the keyboard, the focus is moved to the control with the next highest TabIndex number. The sequence of movement is known as the tab order of the form.
NB: If a control cannot be activated because it is disabled or is a non-interactive element such as a Label then the next control in the tab order that can be activated receives the focus.
Visual Studio Tab Order Control
Manually setting the TabIndex property for every control on a complicated Windows form is time-consuming and prone to error. To make the process simpler, Visual Studio provides a tool that overlays the tab order on a form and allows it to be modified using mouse clicks.
To view the tab order for a form, ensure the form is selected in the form designer and then choose Tab Order from the View menu. The following example shows the tab order for a simple contact management form. Note that within container controls a fractional value is included to show the tab order within the container.
Once the tab order tool has been activated, the tab order can be reassigned by clicking the form controls in the desired order. To stop making changes, simply click the Tab Order command from the View menu for a second time.
10 May 2007