简体   繁体   English

向现有的Tabcontrol C#添加一个Tabcontrol

[英]Adding a Tabcontrol to existing Tabcontrol C#

I'm trying to dynamically add a new Tabcontrol into an existing Tabcontrol . 我试图将新的Tabcontrol动态添加到现有的Tabcontrol I have Categories and Modules. 我有类别和模块。 Every Module is assigned to a Categorie. 每个模块都分配给一个类别。 The Categories are shown in a Tabcontrol . 类别显示在Tabcontrol Now I have to add another Tabcontrol with the Modules(which are Usercontrols) into the existing Tabcontrol with the Categories. 现在,我必须将另一个带有模块(用户Tabcontrol添加到现有的带有类别的Tabcontrol

Thanks for the Help Daniel 感谢您的帮助Daniel

Programmatically this is how you would add a TabControl within a TabControl. 以编程方式,这就是在TabControl中添加TabControl的方式。

private void button1_Click(object sender, EventArgs e)
{
    var parentTabControl = new TabControl {Dock = DockStyle.Fill};
    parentTabControl.TabPages.Add("Parent Tab");
    var page = parentTabControl.TabPages[0]; // Get the index that is appropriate for your logic
    var childTabControl = new TabControl {Dock = DockStyle.Fill};
    childTabControl.TabPages.Add("Child Tab");
    page.Controls.Add(childTabControl);
    this.Controls.Add(parentTabControl);
}

If this doesn't answer you question then please let us know what error you are getting and post the portion of the code which is failing for you :). 如果仍然不能解决您的问题,请让我们知道您遇到了什么错误,并发布代码失败的部分:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM