Copy TabControl Tab(复制 TabControl 选项卡)
问题描述
我在互联网上搜索了这个,但我找不到如何使用 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 选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:复制 TabControl 选项卡


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01