vb.netformstabcontroltabcontainer

How to open a form in a determined tab? vb .net


I have a form with a tabcontrol and 4 tabs. I want to open a form with showdialog in a predetermined tab.

I've tried

    OptionsForm.OPTS_TabControl1.SelectTab(1)
    OptionsForm.OPTS_TabControl1.ShowDialog()

but it didn't work.

Any help? thanks


Solution

  • First Kudos for using Stackoverflow. It shows you paid attention to class =D

    regarding your question, that piece of code you showed should be working. You should provide the actual error so we can try to figure out.

    Does OptionsForm refer to the class or an object of a class you created?

    Anyways, try to create an object of the form and then set the starting tab, like this:

    Dim OptionsObject As New OptionsForm
    OptionsObject.OPTS_TabControl1.SelectTab(1)
    OptionsObject.OPTS_TabControl1.ShowDialog()
    

    Another solution might be Overloading the Showdialog method, although it seems kind of an overshot.

    Here's how: Inside your OptionsForm Code:

    Public Overloads Sub Showdialog(ByRef TabNumber As Integer)
    
    OPTS_TabControl1.SelectTab(TabNumber)
    
    Return MyBase.ShowDialog()
    

    then call the form using

    optionsform.showdialog(1)
    

    Note: Overloading is basically creating another instance of a subrotine that accepts different arguments. read the pages 342-358 of the manual if you wish to know more.