将Tabcontrol添加到现有的Tabcontrol C#中

本文关键字:Tabcontrol 添加 | 更新日期: 2023-09-27 18:19:35

我正在尝试将一个新的Tabcontrol动态添加到现有的Tabcontrol中。我有分类和模块。每个模块都被分配到一个类别中。类别显示在Tabcontrol中。现在,我必须将另一个带模块的Tabcontrol(它们是用户控件)添加到现有的带类别的Tabcontrol中。

谢谢你的帮助Daniel

将Tabcontrol添加到现有的Tabcontrol C#中

从程序上讲,这就是在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);
}

如果这不能回答你的问题,那么请告诉我们你得到了什么错误,并发布代码中对你来说失败的部分:)。