【问题标题】:How to create clone for tabbarpage in tabcontroladv?如何在 tabcontroladv 中为 tabbarpage 创建克隆?
【发布时间】:2015-01-07 05:23:21
【问题描述】:

如何在 tabcontroladv 中为 tabbarpage 创建一个克隆?

我已经创建了克隆,但是更改父控件会反映在克隆控件中。我需要将父控件和克隆控件分开。 我使用了以下代码:

private void button1_Click(object sender, EventArgs e)
{
    TabPage newPage = new TabPage();
    foreach (Control c in  tabControl1.TabPages[0].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);
        }
        newPage.Controls.Add(cNew);
    }

    tabControl1.TabPages.Add(newPage);
}

创建克隆后,父控件中的更改会反映在克隆的控制中。

我可以为此提供样品吗?如何创建克隆。父级的更改不应反映到克隆控件。

【问题讨论】:

  • 这个问题可以用普通的 WinForm TabControl/TabPage 重现吗?

标签: c# winforms syncfusion


【解决方案1】:

是的,可以在 TabBarPage 中克隆控件,因为父 TabBarPage 中的更改不应反映到克隆的 TabBarPage。

TabBarPage newPage;

// To Copy
newPage = new TabBarPage();
foreach (Control c in this.tabBarSplitterControl1.ActivePage.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);
    }
    newPage.Controls.Add(cNew);
}
newPage.Text = "New Tab";

// To Paste
this.tabBarSplitterControl1.TabBarPages.Add(newPage);

示例链接:http://www.syncfusion.com/downloads/support/directtrac/general/Cloning964503659.zip

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 2011-05-06
    • 1970-01-01
    相关资源
    最近更新 更多