将相同的Panel添加到多个TabPage
在我的上一个问题中我可以在运行时将设计时面板添加到选项卡页,我的代码如下所示并且工作正常。
tabControl1.SuspendLayout();
tabControl1.TabPages[0].Controls.Add(panel1);
tabControl1.ResumeLayout();
但现在我需要做这样的事情:
tabControl1.SuspendLayout();
tabControl1.TabPages[0].Controls.Add(panel1);
tabControl1.TabPages[1].Controls.Add(panel1);
tabControl1.TabPages[2].Controls.Add(panel1);
tabControl1.ResumeLayout();
在运行时我可以知道我需要多少个标签页。但现在为了测试,我假设我将有三个标签页
问题是面板仅添加到最后标签页, 我该如何解决这个问题?我希望将其添加到所有选项卡页面 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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?