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 选项卡
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01