复制 TabControl 选项卡

Copy TabControl Tab(复制 TabControl 选项卡)
本文介绍了复制 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 选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)