To Navigate Tabs by Index

Use this board to post your code snippets - tips and tricks
7 posts Page 1 of 1
Contributors
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

To Navigate Tabs by Index
RonaldHarvey
I want to share my little Snips on Tab Navigating by index.
This is how it works.

When the previous button reaches the first tab which is the 0 index and you will click the button again the button Enabled property will become False. The same thing will do if the Tab reaches the last index it will also set the tab Enables property to false.

But if you ckick any Tab with the mouse except the first and the last Tab all buttons will be enabled.

Here are the codes:
Code: Select all
Public Class Tabform

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles  btnPrevious.Click
        If tabExample.SelectedIndex = 0 Then
            btnPrevious.Enabled = False
        Else
            tabExample.SelectTab(tabExample.SelectedIndex - 1)
            btnNext.Enabled = True
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles btnNext.Click
        If tabExample.SelectedIndex = tabExample.TabCount - 1 Then
            btnNext.Enabled = False
        Else
            tabExample.SelectTab(tabExample.SelectedIndex + 1)
            btnPrevious.Enabled = True
        End If
    End Sub

    Private Sub tabExample_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tabExample.MouseClick
        btnNext.Enabled = True
        btnPrevious.Enabled = True
    End Sub
End Class
I hope you like this...Thanks.
Tab Navigation.png
You do not have the required permissions to view the files attached to this post.
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: To Navigate Tabs by Index
MrAksel
Dude there is no indexers for the SelectedTab property, so this wont work at all.
Instead of
Code: Select all
tabExample.SelectTab(tabExample.SelectedIndex + 1)
use
Code: Select all
 tabExample.SelectTab = tabExample.TabPages(tabExample.SelectedIndex + 1)
or
Code: Select all
tabExample.SelectedIndex += 1
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

Re: To Navigate Tabs by Index
RonaldHarvey
Thanks Axel i will try. cooll;
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: To Navigate Tabs by Index
mandai
The code worked for me, but the next/previous buttons needed an extra click to be disabled when they already should be.
You could fix that with this code:
Code: Select all
    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        tabExample.SelectedIndex -= 1
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        tabExample.SelectedIndex += 1
    End Sub

    Private Sub tabExample_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabExample.SelectedIndexChanged
        btnNext.Enabled = Not (tabExample.SelectedIndex = (tabExample.TabCount - 1))
        btnPrevious.Enabled = Not (tabExample.SelectedIndex = 0)

    End Sub
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

Re: To Navigate Tabs by Index
RonaldHarvey
mandai wrote:
The code worked for me, but the next/previous buttons needed an extra click to be disabled when they already should be.
You could fix that with this code:
Code: Select all
    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        tabExample.SelectedIndex -= 1
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        tabExample.SelectedIndex += 1
    End Sub

    Private Sub tabExample_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabExample.SelectedIndexChanged
        btnNext.Enabled = Not (tabExample.SelectedIndex = (tabExample.TabCount - 1))
        btnPrevious.Enabled = Not (tabExample.SelectedIndex = 0)

    End Sub
Excellent mandai the Tab control now works what I really want to happen. Thank you very very very much you're smart. wahooo; wahooo; clapper; clapper; cooll; cooll;
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: To Navigate Tabs by Index
Axel
RonaldHarvey wrote:
Thanks Axel i will try. cooll;
ffs I AM AXEL :P
http://vagex.com/?ref=25000
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

Re: To Navigate Tabs by Index
RonaldHarvey
Axel wrote:
RonaldHarvey wrote:
Thanks Axel i will try. cooll;
ffs I AM AXEL :P
Axel sorry it was supposed to be MrAksel and not Axel in my first post the yellow colored MrAksel confused my eyes too much a sign of my old age.

Thanks for reminding friend. :o
7 posts Page 1 of 1
Return to “Quick Snips”