动态添加标签到 TabControl 容器 [英] Dynamically add tabs to TabControl container

查看:31
本文介绍了动态添加标签到 TabControl 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我希望能够通过使用按钮动态添加选项卡(很像大多数现代浏览器用于添加选项卡的按钮).这些选项卡还应包含一个文本框,该文本框在创建时会拉伸到单个选项卡的宽度和高度.

I have a form in which I would like to be able to add tabs dynamically through the use of a button (much like the buttons most modern browsers have for adding tabs). These tabs should also contain a text box which is stretched to the individual tab's width and height upon creation.

对于缺少代码,我深表歉意,但除了在 Form 类中实例化 TabControl 容器之外,我不知道接下来应该做什么.

I apologise for the lack of code but besides instantiating a TabControl container within a Form class, I have no clue as to what I should do next.

提前致谢.

推荐答案

您只需要在 TabControl.TabPages 集合上调用 Add 方法,然后添加其他该 TabPage 的控件,如下所示:

All you need is to call the Add method on the TabControl.TabPages collection, then add other controls to that TabPage, like so:

    private void button1_Click(object sender, EventArgs e)
    {
        TabPage tp = new TabPage("Test");
        tabControl1.TabPages.Add(tp);

        TextBox tb = new TextBox();
        tb.Dock = DockStyle.Fill;
        tb.Multiline = true;

        tp.Controls.Add(tb);


    }

希望能帮到你

这篇关于动态添加标签到 TabControl 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆