【问题标题】:Adding tabpage to a tabcontrol which is on another form on click of button单击按钮将标签页添加到另一个表单上的标签控件
【发布时间】:2016-03-03 09:40:03
【问题描述】:

我有一个名为 form1 的 winform,它有一个带有一些标签页的 tabcontrol 和一个单击按钮,我打开另一个名为 form2 的表单。我想通过单击 form2 上的按钮将 tabpage 添加到 form1 tabcontrol。

【问题讨论】:

  • 嗨,Dinesh,您能提供到目前为止您尝试过的任何代码等吗?你遇到过什么问题?看看我们关于提出好问题的快速指南:stackoverflow.com/help/how-to-ask

标签: winforms


【解决方案1】:

假设您没有在运行时在 Firstform 中创建 tabcontrol。

在 FirstForm.cs 中

    private void button1_Click(object sender, EventArgs e)
    {
        SecondForm obj = new SecondForm(this);
        obj.Show();
    }

    public void addTabpage()
    {
        TabPage tbpg = new TabPage();
        tbpg.Text = "New tabpage";
        tabControl1.TabPages.Add(tbpg);

        this.BringToFront();
    }

在SecondForm.cs中,改变构造函数如下

    static FirstForm objpub;
    public SecondForm(FirstForm obj)
    {
        InitializeComponent();
        objpub = obj;
    }
    private void button1_Click(object sender, EventArgs e)
    {
        if (objpub != null)
        {
            objpub.addTabpage();
        }

    }

如果此答案不符合您的问题,请提供您的代码。 干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2016-10-16
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多