Forms Inheritance in VB.Net
Introduction
In this article we learn how to take advantage of Forms Inheritance, while being introduced to certain Object Oriented approaches.A major change occurred for VB programmers when Microsoft announced that the launch of their new VB.NET was to become the successor for the Visual Basic programming language.
Due to the lack of the power of INHERITANCE, the Microsoft decided to implement inheritance in VB.NET. We need a new form in our applications we create a new instance of the System.Windows.Forms.Form class, change its properties to suit our needs, place some controls and our form is ready for use. As we know, by placing some controls onto a new form, we extend the forms class to NewForm1, meaning we have created a new class with a name NewForm1. Our new form is a class; we can extend any class due to inheritance supported in .NET.
Here we can conclude that we can design the base form and use the base form design in all our forms:
Base Form:
Public Class PMainForm
Inherits System.Windows.Forms.Form
Child Forms:
Public Class Child1
Inherits PMainForm
The Child Forms can be used in the ways we desired. Things we can do with our child forms: override the functionality of the base form within the child form itself (i.e. using Shadows keyword in our functions in the child form – we will also see this in detail later on in this article), we can add custom properties to our base form and set them in the child forms (for controlling the controls which originally do not exist in the parent form) and anything else we’d like.