How can I with Tabcontrol select/focus any TabPage
-
How can I with Tabcontrol select or focus any TabPage with code. I don't know how do this. Johnny
You can do this using the SelectedIndex of the TabControl. SelectedIndex will get or set the Index of the currently selected tab. For example, the following code assumes that there is a Button and a TabControl on the form. The Button is used to select the next tab in the TabControl.
Dim currentTab As Integer Dim highestTab As Integer Private Sub cbNext\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNext.Click Dim nextTab As Integer = currentTab + 1 If nextTab > highestTab Then nextTab = 0 End If TabControl1.SelectedIndex = nextTab currentTab = TabControl1.SelectedIndex End Sub Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load currentTab = TabControl1.SelectedIndex highestTab = TabControl1.TabCount - 1 End Sub
RageInTheMachine9532
-
You can do this using the SelectedIndex of the TabControl. SelectedIndex will get or set the Index of the currently selected tab. For example, the following code assumes that there is a Button and a TabControl on the form. The Button is used to select the next tab in the TabControl.
Dim currentTab As Integer Dim highestTab As Integer Private Sub cbNext\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbNext.Click Dim nextTab As Integer = currentTab + 1 If nextTab > highestTab Then nextTab = 0 End If TabControl1.SelectedIndex = nextTab currentTab = TabControl1.SelectedIndex End Sub Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load currentTab = TabControl1.SelectedIndex highestTab = TabControl1.TabCount - 1 End Sub
RageInTheMachine9532
I just want to know ,how can i use this code on TAB select,i have been trying this on Tab select,instead of Button click,in order to get effect this on Tab select ,On which event should i write the code.u can mail me shihab@vatimsolutions.com...Thanxs in advance.
-
I just want to know ,how can i use this code on TAB select,i have been trying this on Tab select,instead of Button click,in order to get effect this on Tab select ,On which event should i write the code.u can mail me shihab@vatimsolutions.com...Thanxs in advance.
The code I submitted was an example of how to change the Tab in code. You can use the same code in a different routine if you want. Just the most important part was TabControl1.SelectedIndex = (tab number). The rest was just keeping track of which tab was selected and what the next tab number is. Using the TabPage.Select method doesn't work the way you would expect it to. The user won't see any change in the tab that is shown if you use that method. RageInTheMachine9532