Inheritance and Windows Forms - Exploring Forms
(Page 2 of 5 )
Now let’s explore the “Forms” folder in under the project. As you can see, there are three forms: “ManageEmployees”, “ManageManagers”, and “ManageTechnicians”. If you view the code in the “ManageManagers” or the “ManageTechnicians” forms, then you will see that these forms inherit from the “ManageEmployees” form.
Here is how we add an inherited form.
1) Right click on the project and select “Add” -> “Add Windows Form”, and name it “ManageEmployees”
2) Before adding the inherited form, make sure you “Build” the project.
3) Right click on the project and select “Add” -> “Add Inherited Form”, and name it “ManageManagers”. In the “Inherit Picker” chose the form that we want to inherit from , and in this case it is “ManageEmployees”
4) Do the same step for the form “ManageTechnicians”.
What we have done so far is the following:
1) We added classes “Manager” and “Technician”, which inherit from the “Employee” Class.
2) We added forms “ManageManagers” and “ManageTechnicians”, which inherit from the “ManageEmployees”.
Now, here is the beauty of the inheritance in windows form. We will be working on the “ManageEmployees” form only, and this will be reflected on the other forms since we have the inheritance relation (remember?).
1) Let’s set some properties on the “ManageEmployees” form:
a. ControlBox = False
b. FormBorderStyle = FixedDialog.
2) Add 2 labels to the form (lblName, lblAge).
3) Add 2 text boxes to the form (txtName, txtAge).
4) Add a button (btnAdd).
5) And finally add an Error Provider (errProvider).
If you want to set the properties of the controls on the form, then please check them on the project.
Before we move on, please make sure to “Build” the project. If you check the “ManageManagers” or the “ManageTechnicians” forms, you will find out that they have the same properties and the controls that are available on the “ManageEmployees” form. No magic was done, it is the inheritance.
Next: Validating Inputs >>
More Visual Basic.NET Articles
More By Mohammed Qattan