How to display the same control on two different tabs?

谁说胖子不能爱 提交于 2019-12-07 02:24:08

问题


I'm using VB.NET

I need same control (ListBox) to be displayed on 2 different tabs.

Is it mandatory to create 2 different ListBox instances?


回答1:


If you don't need design-time support you can simply, at runtime, change the ListBox instance's Parent from one tab to the other (making sure to set the positioning appropriately, of course).

Essentially, it's:

listBox1.Parent = tabControl1.TabPages[1];

In the end though, you'll probably find it easier to just have two ListBox's with the same data source.




回答2:


Yes, I think you'll need a ListBox control on each tab. If they have the same data you can use the same DataSource for both though.




回答3:


Yes, add a new instance on each tab.




回答4:


If you want full designer support, you'll need two boxes. If doing it in code is enough, you can create a single listbox on form load, and manually add a reference to it to each tab page.



来源:https://stackoverflow.com/questions/513276/how-to-display-the-same-control-on-two-different-tabs

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