Windows Form Inheritance

I want to create a bunch of forms that have the same properties and initialize the properties in the form designer by assigning constructor parameters.

I tried to create a class that inherits from the form, and then all my forms inherit from this class, but I think, since I could not call InitializeComponent (), that I had some problems.

What is C # code, how to do it?

+5
source share
3 answers

Parent InitializeComponentshould be called by calling your constructor base()as follows:

public YourFormName() : base()
{
    // ...
}

( InitializeComponent . , ?)

, , , , , ( ). , , , .

, . .

+6

factory . , factory

+1

Create an interface and pass it to the form constructor.

interface IFormInterface
{
      //Define Properties here
}

public MyForm(IFormInterface AClass)
{
      //Set Properties here using AClass
}

Although I usually do more than just set properties when I want to do something like this, I therefore create an abstract class for the default behavior.

0
source

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


All Articles