通过单击按钮将标签页添加到另一个表单上的标签控件 [英] Adding tabpage to a tabcontrol which is on another form on click of button

查看:28
本文介绍了通过单击按钮将标签页添加到另一个表单上的标签控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 form1 的 winform,它具有带有一些 tabpages 的 tabcontrol 和一个单击按钮,我打开另一个名为 form2 的窗体.我想通过单击 form2 上的按钮将 tabpage 添加到 form1 tabcontrol.

I have a winform called form1 which has tabcontrol with some tabpages and one button on clicking of which I open another form called form2. I want to add tabpage to form1 tabcontrol on click of button which is present on form2.

推荐答案

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

Assumed that you have not created a tabcontrol at runtime in the Firstform.

在 FirstForm.cs 中

In 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中,修改构造函数如下

In SecondForm.cs, change the constructor as follows

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

    }

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

If this answer does not meet your problem, then provide your code. Cheers !

这篇关于通过单击按钮将标签页添加到另一个表单上的标签控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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