1

I'm a beginner in Visual Studio and i'm developing a WinForm using VB.NET. I would like to have child forms to inherit controls as menu strips or tool strips without creating the same ones over and over as i pass to other forms.

In old VBA i could do that with multipage, just changing the bottom part of the form without touching the rest, but is that possible in Visual Studio? As previously said i'm a beginner so i hope in detailed answers.

sickboy
  • 11
  • 3
  • If you did this in VBA then you may be misunderstanding the concept of inheritance in OOP. VBA (or VB6) had no ability to inherit (although interfaces provided a workaround for achieving some level of code reuse, they were not the same as true inheritance) – Julian May 18 '23 at 13:14

1 Answers1

3
  1. Add a new form.
  2. Click the Show All Files button in the Solution Explorer.
  3. Expand the node for the form.
  4. Open the designer code file.
  5. Edit the Inherits line to inherit your desired base form instead of the standard Form class.

That's all there is to it. Inheritance works the same way all the time.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • so i should comment the line "Inherits System.Windows.Forms.Form" and add e.g. "inherits Form1.Menustrip1" ? – sickboy May 17 '23 at 10:54
  • 1
    @sickboy, you should do what I said to do. I said *"inherit your desired base form"*. Is `Form1.MenuStrip1` your desired base form? Given that it's not a form at all, the answer is obviously "no". What is the form you want to inherit? That's what you put there in the line that specifies what the current class inherits. – jmcilhinney May 17 '23 at 11:06
  • Ok so I guess you meant to create a base form which allows other forms to inherit all of its controls without distinctions. This i think sounds clearer. Thank you for your clarification. – sickboy May 17 '23 at 13:23