Doz*_*789 6 c# tabs tabcontrol winforms
我在互联网上搜索了这个,但我找不到如何用C#做到这一点
我想要做的是,当我点击我的NewTab按钮时,会出现一个新选项卡,其中包含第一个选项卡上的相同控件.我看到了一些关于如何向UserControl表单添加内容的信息,但C#没有这样的内容.
对于每个会说"发布你的代码"的人,我都没有,所以不要说这个,我唯一的代码是程序的代码,这对任何人都无济于事.
我已经重写了我的解决方案以使用反射.
using System.Reflection;
// your TabControl will be defined in your designer
TabControl tc;
// as will your original TabPage
TabPage tpOld = tc.SelectedTab;
TabPage tpNew = new TabPage();
foreach(Control c in tpOld.Controls)
{
Control cNew = (Control) Activator.CreateInstance(c.GetType());
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(c);
foreach (PropertyDescriptor entry in pdc)
{
object val = entry.GetValue(c);
entry.SetValue(cNew, val);
}
// add control to new TabPage
tpNew.Controls.Add(cNew);
}
tc.TabPages.Add(tpNew);
Run Code Online (Sandbox Code Playgroud)
有些信息可以在这里找到. http://www.codeproject.com/Articles/12976/How-to-Clone-Serialize-Copy-Paste-a-Windows-Forms