How to Dynamically Create Tabs

纵然是瞬间 提交于 2019-11-29 15:33:55

问题


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.


回答1:


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();



回答2:


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;


来源:https://stackoverflow.com/questions/3737123/how-to-dynamically-create-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!