Click here to Skip to main content
15,942,757 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have in WinForm Tabcontrol I have a Tabcontrol with 6 TabPages and two Buttons.
The First Button 'Next' and another Button 'Back'.
When I click 'Next' I want to go to next TabPage, when I click Back I want to go to the previous TabPage.

How do that By TabIndex for TabPage....
Espen Harlinn 15-Jan-11 8:49am    
You've already asked this question :, You'll find the rest of what you need to know at this location:

1 solution


from microsoft docs about TabIndex property:
TabPage controls are contained within TabControl controls, however, and do not receive focus individually as part of the form's TAB order. This property is therefore meaningless for this class.

So use SelectedIndex :

Next button :
yourTabControl.SelectedIndex += (yourTabControl.SelectedIndex == 5 ? 0 : 1);

Back button :
yourTabControl.SelectedIndex -= (yourTabControl.SelectedIndex == 0 ? 0 : 1);
Share this answer
Espen Harlinn 15-Jan-11 9:09am    
5+ nice handling of yourTabControl.SelectedIndex
fjdiewornncalwe 15-Jan-11 14:31pm    
+5. One suggestion, however is that instead of the hardcoded "== 5" to use " < yourTabControl.TabPages.Count"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900