Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can I with Tabcontrol select/focus any TabPage

How can I with Tabcontrol select/focus any TabPage

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jlizardo
    wrote on last edited by
    #1

    How can I with Tabcontrol select or focus any TabPage with code. I don't know how do this. Johnny

    D 1 Reply Last reply
    0
    • J jlizardo

      How can I with Tabcontrol select or focus any TabPage with code. I don't know how do this. Johnny

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        U Offline
        U Offline
        User 765502
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • U User 765502

          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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups