views:

67

answers:

2

This is in C#

I Need to basically make TabPages from a textbox.Text so for example:

textBox1.Text = "test";
TabPage textBox1.Text = new TabPage();

That is what i want to do.. i know that won't work directly, but that should give you the idea of how i want to create the tabPages.. then i want to be able to call them later on too so for example:

String browser = "browser 1";
(textBox1.Text as TabPage).Controls.Add(WebBrowser browser)

I need all the names to be dynamic because what this will be is a program that can run tests for customer accounts There would be a TabControl which has the "Account Number as the tabPage control name and then inside each of those tabPages would be another TabControl with a set up tabs with each invidivual test in it's own tab. So Tabs within Tabs basically.

+2  A: 

Make it look similar to this:

        var page = new TabPage(textBox1.Text);
        var browser = new WebBrowser();
        browser.Dock = DockStyle.Fill;
        page.Controls.Add(browser);
        tabControl1.TabPages.Add(page);
        browser.Navigate("http://stackoverflow.com");
        page.Select();
Hans Passant
This created the tabPage, but it didn't actually select the tab
Alex
@Alex: You want tabControl1.SelectedTab = page;
w69rdy
Looks like that worked, i think this is what i need, but i'll need to do some tinkering... Thanks guys!
Alex
A: 

Actually one other thing i want to know, How can i call on this Tab @ another time outside of this function?

This is basically what i turned out to look like.

String browserName = "Test Check";
var tabPageName = new TabPage(textBox1.Text);
var tabPageBrowser = new TabPage(browserName);
var tabPageTabControl = new TabControl();
var browser = new WebBrowser();
tabPageName.Controls.Add(tabPageTabControl);
tabPageTabControl.TabPages.Add(tabPageBrowser);
tabPageBrowser.Controls.Add(browser);
mainTabControl.TabPages.Add(tabPageName);
mainTabControl.SelectedTab = tabPageName;
Alex
Use variables or fields to hold a reference to the object you want to address later on. Dude, this is very basic stuff. Have a look at some tutorials. C# class : http://msdn.microsoft.com/en-us/library/0b0thckt(v=VS.100).aspx
matthew.perron
The reason i ask is because if i try something like MessageBox.Show(mainTabControl.SelectedTab.Name.ToString());It comes up blank, so i dont see how i'm able to call that tab later on
Alex
That's because you aren't assigning a name to the new tab page control, you are only assigning text. In order for mainTabControl.SelectedTab.Name to return anything, you have to have tabPageName.Name = textBox1.Text;
kevev22
nevermind, i had a brainfart... tabPageName.Name = textBox1.Text;
Alex