Visual Inheritance in vb.net

In this tutorial, I’ll show you how you could inherit visual objects in vb.net.

Inheriting visual objects, means that you need a ‘base form’ which you will inherit from and a form which would inherit from that base form (I forgot what its called, if you know it feel free to comment)

Add up visual elements in your base form (buttons, textboxes, groupbox, tab control, etc).

Then make a new windows form which would inherit from the base form which you have just made.

After that, click on the ‘show all files’ option on your solution explorer on the upper right pane of your visual studio window.

image

Expand the Form which will inherit from the base form, then double click on the file with ‘.Designer.vb’ extension. In my case, its named Main.Designer.vb since the name of my form is Main.

After double-clicking, you would see something like this:

image

The point of interest is the one that I have highlighted, obviously.

Inherits WindowsApplication3.Form1

Now, change this line of code to fit yours.

Just change the WindowsApplication3 to the actual name of the project which you have created. The one that is on the uppermost part of the solution explorer:

image

Then change the Form1 to the actual name of the base form that you have created.

That’s it, now you won’t have to copy and paste the same visual elements to each of your forms just to have a consistency in your application. Just do the same to all of the forms that needs to inherit from a base form.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s