What determines the tab order when more controls have the same tabindex
property?
For example, after adding a texbox to an empty form the texbox's tabindex
was 0. By duplicating the texbox (Ctrl mouse drag) the new textbox had tabindex
0 too. Then I added a button and its tabindex
was 1.
After running the program the focus was on the 2nd textbox.
Then I changed button's tabindex
to 0 so after that all controls had tabindex
= 0 and after running the program the focus was on the button which was added last.
Does that mean that in case of multiple controls with the same tabindex
property the tab order will be the opposite of order of adding the controls to the form? Seems as the tab order of the controls which share the same tabindex
is just the opposite of their order of appearance in Form.Designer.cs
file.
Or is it that button control always has priority over textbox control when they both share the same tabindex
?
Is that documented somewhere?
CodePudding user response:
From MSDN Control.TabIndex Property
A tab index can consist of any valid integer greater than or equal to zero, lower numbers being earlier in the tab order. If more than one control on the same parent control has the same tab index, the z-order of the controls determines the order to cycle through the controls.
And a bit of a nuance as well:
For a control to be included in the tab order, its TabStop property must be set to true.
So, you're seeing controls with the same TabIndex
value tab in reverse order from the code behind file due to the z-index value.