問題描述
我在互聯網上搜索了這個,但我找不到如何使用 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.
推薦答案
編輯
我已經重寫了使用反射的解決方案.
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/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 選項卡的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!