How do you get the PreviousTab in a tab control in

Posted on 2007-10-11
Last Modified: 2013-11-26
In VB6 we had

Private Sub SSTab1_Click(PreviousTab As Integer)

end sub

Can we get the previous tab in VB.Net, or is this something we have to set up manually?
Question by:grwallace
    LVL 48

    Expert Comment

    I think we have to do it manually! At least I do it and I don't know another way.
    LVL 2

    Expert Comment

    There are several events available on the Tab control, the most promising one is -

    Public Event Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
         Member of: System.Windows.Forms.TabControl
    Occurs before a tab is selected, enabling a handler to cancel the tab change.

    If the TabControlCancelEventArgs, contains the tab / index which is going to  be selected, then you can get the currently selected tab / index from the Tab control and the going-to-be-selected from the TabControlCancelEventArgs.

    Author Comment

    I'm not sure how to extract the value from the TabControlEventsArg, but this looks like what I want
    LVL 2

    Accepted Solution

    I tried out on a project ------ actually the event you are looking for ------ if you want to cancel navigation to some other tab, then you can use the Deselecting event on the TabControl --- here is a snippet

    Private Sub TabControl1_Deselecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Deselecting

    End Sub

    If I am on TabPage 1, and click on TabPage 2, then it shows 0 and 0 respectively ----- which means, that I cannot find out which the next-tab-is-going-to-be........

    This event, does allow you to cancel the navigation ------ you can use e.Cancel = True

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now