I have a tab control which contains a set of controls like list boxes,buttons and a chart control. Is there a possibility of adding another tab, making the new tab to comprise of all the controls that the first tab contained.?
Asked
Active
Viewed 662 times
0
-
1duplicate http://stackoverflow.com/questions/10266589/clone-controls-c-sharp-winform – VladL Mar 06 '13 at 08:36
-
@Vlad L Thank you for the idea.It would work fine. But in my case i need to create multiple such tabs containing the controls. And i do not know before run time how many such tabs would be needed. So is there a way to do this? – Praveen Dinks Mar 06 '13 at 10:08
-
so you want to create multiple tabs with exactly the same content? – VladL Mar 06 '13 at 10:10
-
@Vlad L Yes, you are right. I need the same controls. Though small content changes would be there. For example, the chart content could be different in each tab.Any suggestions? – Praveen Dinks Mar 06 '13 at 10:17
1 Answers
1
Based on your comment you are better to create a usercontrol. After creating it once, you can simply add it to the new tab like this:
TabPage tp = new TabPage("new tp");
MyUserControl muc = new MyUserControl();
tp.Controls.Add(muc);
tabControl1.TabPages.Add(tp);
int tabIndex = 1;
You can access the properties of each tab like this:
int tabIndex = 1;
MyUserControl contr = tabControl1.TabPages[tabIndex].Controls[0] as MyUserControl;
contr.MyGraph = ...

VladL
- 12,769
- 10
- 63
- 83
-
Thank you so much. This works for me. But could i know how i can access the controls of the second tab using code? – Praveen Dinks Mar 06 '13 at 10:41