Adding the same Panel to multiple TabPages

孤街醉人 提交于 2019-12-11 06:01:14

问题


In my previous question I could add a design time panel to a tab page at run time and my code looks like this and it works Ok.

        tabControl1.SuspendLayout();
        tabControl1.TabPages[0].Controls.Add(panel1);
        tabControl1.ResumeLayout();

but now I need to do something like this:

    tabControl1.SuspendLayout();
    tabControl1.TabPages[0].Controls.Add(panel1);
    tabControl1.TabPages[1].Controls.Add(panel1);
    tabControl1.TabPages[2].Controls.Add(panel1);
    tabControl1.ResumeLayout();

which just at run-time I can know how many of these Tabpages I will need. but now for testing I am assuming I will have three tabPages

the Problem is that the panel only gets added to the Last tabPage, How can I fix this? I want it get added to all of the tab pages Thanks.


回答1:


You can't. A control can have only one parent at a time. Luckily, only one tab page is visible at a time, so I guess you could move the panel between the pages as they are displayed? On the other hand, if the panel is to be located in the same place for all pages, perhaps it should not be placed inside the tab control, but rather on top of it?



来源:https://stackoverflow.com/questions/2953382/adding-the-same-panel-to-multiple-tabpages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!