C# Tab Control - Inherit from TabPage?
Basically, I am creating a Windows Form with a Tab Control on it, and I want to have multiple types of tab pages for the different types of objects I will be editing the properties of. Basically like interface in Visual Studio, where you can have multiple 开发者_如何学Gotab pages of code, then multiple tabs of resource files, etc.
To do this, I figure that I will need to:
- Create a class inheriting from TabPage for each type of tabpage layout I would like.
- Make each of these classes accept a certain type of object in the constructor.
- In the constructor, create all the controls for that tab page and set the properties.
However, this means that I cannot design the tab pages in Visual Studio (I will need to code the layout by hand).
Am I going about this the correct way? Or is there a different way to approach this problem?
Have you considered creating a Custom Control for each type of page that you want to display? Rather than having different types of tabs, you can then use Visual Studio to design the layout of each custom control (along with any code that is per-tab), and when a new tab is created, make its sole child control an instance of the relevant type of custom control.
Advantages:
- This allows you to use VS to design the look and feel of the tab contents
- If you want to re-use the UI for the contents of the tab elsewhere, it's already decoupled from the tab control (this would even help if at a later date you moved to using windows instead of tabs, for example).
精彩评论