简体   繁体   中英

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 tab pages of code, then multiple tabs of resource files, etc.

To do this, I figure that I will need to:

  1. Create a class inheriting from TabPage for each type of tabpage layout I would like.
  2. Make each of these classes accept a certain type of object in the constructor.
  3. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM