C # Tab Control - Inherit from TabPage?

Basically, I am creating a Windows Form with a Tab control, and I want to have several types of tab page for different types of objects, which I will edit with properties. Basically, as an interface in Visual Studio, where you can have several pages of code tabs, then several tabs of resource files, etc.

To do this, I suppose I need:

  • Create a class that inherits from TabPage for each type of tab layout I would like.
  • So that each of these classes accepts a certain type of object in the constructor.
  • In the designer, create all the controls for this bookmark and set the properties.

However, this means that I cannot create tab pages in Visual Studio (I will need to copy the layout manually).

Am I right about this? Or is there another way to approach this problem?

+4
source share
1 answer

Have you considered creating a custom control for each type of page you want to display? Instead of having different types of tabs, you can use Visual Studio to design the layout of each custom control (along with any code that is behind the tab), and when a new tab is created, make your only child control an instance of the appropriate type of user control .

<strong> Benefits:

  • This allows you to use VS to design the appearance of the contents of the tab.
  • If you want to reuse the user interface for the contents of the tab in another place, it is already separated from the tab control (this would even help if you later switched to using windows instead of tabs, for example).
+2
source

Source: https://habr.com/ru/post/1302345/


All Articles