Salman Mushtaq
Salman Mushtaq

Reputation: 341

How to re-arrange controls in winforms c#

I search my question on but I didn't get answer so I decide to post a question.

My Scenario

I have a win form that have 10 controls (Textbox, labels, combobox etc) when I open the form the focus is on first textbox, I press TAB and focus move to 2nd textbox. In this way I have textbox 1, textbox 2 up to textbox 10.

My Issue

Now I add textbox 11 in mid of textbox 3 and textbox 4, and now when I press Tab after textbox 3 the control move to textbox 4 instead of textbox 11, I didn't want to copy all control after textbox 11 and paste it again. Is there any way I can re-arrange the control sequence?

Looking forward to your responses. Advance thanks.

Best Regards - Salman

Upvotes: 0

Views: 1332

Answers (4)

Steve
Steve

Reputation: 216243

The tab order is controlled by the TabIndex property and you can set this property manually, but Visual Studio gives you a very useful tool to rearrange your tab order. Just open a form in its designer window then go to the View Menu and select Tab Order.

You will see a little box with a number inside along all controls that can receive the focus at runtime (yes even the labels have this number because you can insert the & character behind any label's text letter as a shortcut for ALT+letter to reach the control following the label in the tab order)

Now you can start clicking on these numbers to rearrange the tab order of the controls.

In your case just start clicking the number for the misplaced textbox until it reaches the correct order then continue clicking on the remainder controls to increase their order one by one

Here an example of a disordered form

disordered form

Now, to reorder it, I just start clicking on the 14 box until it becomes 6 then I continue clicking on the 15 box to get the 7 value, finally go on with the current 6 to get 8 and so on until I reach the final buttons

Upvotes: 2

Idan Fanous
Idan Fanous

Reputation: 29

First option is to change the TabIndex property value.

Second option is to go to View -> Tab Order and then click the controls in the order you want them to be.

Upvotes: 2

Ashkan Mobayen Khiabani
Ashkan Mobayen Khiabani

Reputation: 34152

Tab moves in the order of the TabIndex property of the controls. just sort thier TabIndexes.

Upvotes: 1

You can set the TabIndex property of the controls to match your desired order.

Upvotes: 4

Related Questions