There are several similar forms (size, background, 1 button), to each of which different elements are added: to one - textbox, to the other - pictures, to the third - a few more buttons. How to organize it correctly?

  • What is the actual problem? You can make Copy / Paste - iluxa1810
  • While I made one form with a background and a button, and the others inherit from it. But ideally, it would be to set something like a class - so that the form had all the necessary components, and only some were called at each initialization - Elena
  • Well, you can hide unnecessary elements of Form.Visible = false . Form.Visible = false . There are many possible solutions. - rdorn
  • How about a named constructor? All interface elements are placed on the form, and the callee constructor determines what to display on the created form? - iluxa1810
  • ru.stackoverflow.com/a/574140/198316 paragraph 2 look. Inheritance is quite a working version, if you of course correctly selected the general functionality. The variant with inheritance is applicable to the variant by reference. - rdorn

1 answer 1

As an option, it is to place all the elements in a hidden state on the form. In the form class, you need to implement the named constructors (Factory Method), which will create the form with the necessary functionality.

  • here, rather, you need a custom property that allows you to select a preset that activates the necessary elements, factories IMHO a little for another. But also a working version. - rdorn