Copy TabControl Tab

后端 未结 3 436
别那么骄傲
别那么骄傲 2020-12-10 16:21

I searched the internet for this but i couldn\'t find how to do it with C#

What i am trying to do is make it so that when i click on my NewTab button, a

3条回答
  •  一整个雨季
    2020-12-10 16:57

    Your best bet would be to look at this article:

    Code Project

    Then apply the following code to add the cloned control (this would be in your button click handler code (based on article):

        private void button1_Click(object sender, EventArgs e)
        {
            // create new tab
            TabPage tp = new TabPage();
    
            // iterate through each control and clone it
            foreach (Control c in this.tabControl1.TabPages[0].Controls)
            {
                // clone control (this references the code project download ControlFactory.cs)
                Control ctrl = CtrlCloneTst.ControlFactory.CloneCtrl(c);
                // now add it to the new tab
                tp.Controls.Add(ctrl);
                // set bounds to size and position
                ctrl.SetBounds(c.Bounds.X, c.Bounds.Y, c.Bounds.Width, c.Bounds.Height);
            }
    
            // now add tab page
            this.tabControl1.TabPages.Add(tp);
        }
    

    Then you would need to hook the event handlers up. Will have to think about this.

提交回复
热议问题