复制TabControl的标签 [英] Copy TabControl Tab
问题描述
我搜索了上网本,但我找不到如何用C#做
I searched the internet for this but i couldn't find how to do it with C#
什么,我要做的是让这个当我点击在我的 NewTab
按钮,一个新的选项卡会显示与是第一个选项卡上的相同的控制。我看到如何添加用户控件
来的形式,但是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.
推荐答案
我已经重写我的解决方案使用反射。
EDIT
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 /条/ 12976 /如何对克隆序列化 - 复制 - 粘贴-A-Windows的窗体
这篇关于复制TabControl的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!