Everything You Wanted to Know About Forms Inheritance in VB.Net - Visual Inheritance
(Page 3 of 6 )
We now know how to create objects of classes. Just in a similar fashion, we can also inherit from a form.
Is it possible to inherit the components of the parent form?
Yes, it is possible. But inheriting the controls does not mean that we are able to view the controls in the child forms because we inherit the controls, and not the properties of those controls, which we had set into the Parent form. Suppose we have placed a Button in the Parent form, and its top position is at 200px. This does not depict that if we inherit the Parent Form for the child class then we will be able to see the same Button at the same position (i.e. Button1.Top = 200).
So, How does this all happen? How are we able to see the controls of the parent form at the same location in the child form?
VS.NET does this by repositioning the controls in the child form. You can experience this. Go and change the position in the Parent Form, but don’t build the Parent form. Now open the Child Form and see the difference in the position of the Button, it is at the previous position.
This mean that the position of the button has not changed even if we have changed it in the parent form. So what VS.NET does is it resets the properties of the Controls in the Child Form, when we compile the Parent Form.
Now you understand how VS.NET incorporates Visual Inheritance.
Next: What’s New in This Article >>
More VB.Net Articles
More By Saurabh Verma