我在互联网上搜索了这个,但我找不到如何使用 C# 来完成它
I searched the internet for this but i couldn't find how to do it with C#
我想要做的是,当我点击我的 NewTab
按钮时,会出现一个新标签,其中包含与第一个标签上相同的控件.我看到了一些关于如何将 UserControl
添加到表单的信息,但 C# 没有类似的东西.
What i am trying to do is make it so that when i click on my NewTab
button, a new tab appears with the same controls that were on the first tab. I saw some information on how to add a UserControl
to your form, but C# doesn't have anything like that.
对于每个会说发布你的代码"的人,我没有,所以不要费心这么说,我唯一的代码是程序的代码,这对任何人都没有帮助.
And for everyone who would say "Post your code", i don't have any, so don't bother saying that, the only code i have is the code for the program and that wouldn't help anyone.
我已经重写了使用反射的解决方案.
I have rewritten my solution to use reflection.
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);
一些信息可以在这里找到.http://www.codeproject.com/Articles/12976/How-to-Clone-Serialize-Copy-Paste-a-Windows-Forms
Some information can be found here. http://www.codeproject.com/Articles/12976/How-to-Clone-Serialize-Copy-Paste-a-Windows-Forms
这篇关于复制 TabControl 选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!