Click here to Skip to main content
15,880,608 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....
Posted
Comments
Espen Harlinn 15-Jan-11 8:49am    
You've already asked this question : http://www.codeproject.com/Questions/146529/TabControl-in-my-Project.aspx, You'll find the rest of what you need to know at this location:http://msdn.microsoft.com/en-us/library/dd30h2yb.aspx

1 solution

Really,

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
 
v4
Comments
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