c sharp windows应用程序,动态地将数据添加到选项卡控件 [英] c sharp windows application, adding data to tab control dynamically

查看:93
本文介绍了c sharp windows应用程序,动态地将数据添加到选项卡控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我接受了用户控制,我接受了所有控件,我添加了tab contol

,用于通过用户控件动态添加所有数据

我在选项卡控件中编写代码但是它不起作用。



我在哪里可以编写代码

Hi i took user contol, I took all controls and I added tab contol
for dynamically adding all data through user control
I wrote the code in tab control but it's not working.

Where can i write that code

void AddTab()
{
    TabPage tbp = new TabPage();
   
                tbp.Name=tabControl1.TabPages.Count.ToString();
UserControl1 cnt=new UserControl1();

   
                cnt.Name="Cnt" + tbp.Name;
    cnt.Dock=DockStyle.Fill;
    tbp.Controls.Add(cnt);
}




?

推荐答案

你在tabpage中添加usercontrol ...

,但你错过了在tabcontrol1中添加tabpage

you are adding usercontrol in tabpage...
but you miss adding tabpage in tabcontrol1
void AddTab()
{
    TabPage tbp = new TabPage();

    tbp.Name = tabControl1.TabPages.Count.ToString();
    UserControl1 cnt = new UserControl1();

    cnt.Name = "Cnt" + tbp.Name;
    cnt.Dock = DockStyle.Fill;
    tbp.Controls.Add(cnt); //you are adding usercontrol in tab page
                
    tabControl1.TabPages.Add(tbl); //but you miss adding tabpage in tabcontrol1
}



快乐编码!

:)


Happy Coding!
:)


这篇关于c sharp windows应用程序,动态地将数据添加到选项卡控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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