Click here to Skip to main content
13,189,324 members (66,907 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 13 May 2004

Creating Template Forms using Visual Inheritance

, 13 May 2004
Rate this:
Please Sign up or sign in to vote.
Understanding visual inheritance in .NET and creating generic Template forms using visual inheritance.


As we know, in OOP’s, Inheritance is the ability to use all of the functionality of an existing class, and extend those capabilities without re-writing the original class. Basically, it means one object to inherit another object’s methods and properties.

In .NET, inheritance is not just limited to designing classes but also extended to visual designing. So, what does it mean? Well, it means we can use inheritance in Form designing too, so this kind of usage is called Visual Inheritance.

But Visual Inheritance of Windows Forms is still inheritance based on classes. One has to keep in mind all other inheritance features while using visual inheritance. For example, if you create methods and properties in base classes, one has to take care which of them can be overridden by derived classes.

One of the main advantages of visual inheritance is it reduces or cuts down the development time, and helps in designing consistency in the Forms layouts.

In most of the application development, you find common appearance in the form layout. Technically speaking, it’s basically a Form Templates concept followed in the application design to give the same appearance throughout the product.

Most of the developers spend their time in designing the form layouts during the application development. So, with the usage of visual inheritance, developers can cut down the time & cost.

Following below are some of the areas where you can use visual inheritance in form designing:

  • Forms having common menu structure
  • Forms having common graphic images and buttons
  • Form's behavior has to be changed depending on usage
  • Forms which require common code

Using visual inheritance, however, you could create a Template form containing all your common controls, along with common code .Then, you can derive new forms from your Template base form that provide the appropriate functionality.

Let me explain this with a small example:

In the sample application, we will assume most of the forms should have same look and feel in UI. So, let’s create a Template form which has a menu bar, logo and buttons which will be common for all the forms. Figure.1 shows the Template form.


Figure [1]. Template.vb

In the sample application Visual Inherit, we will create a Form inheriting from Template.vb. Figure [2] shows the inherited form called FormsUsingTemplate.vb.


Figure [2]. FormsUsingTemplate.vb

To inherit from Template.vb form, all you need to do is right click project’s Solution Explorer and select the “Add New Item” and then select “Inherited Form”. Once you select “Inherited Form”, you will see an Inheritance Picker dialog box showing all the forms available in the project, and we will select Template Form for our sample, as shown in below Figure [3].

Inheritance Picker

Figure [3]. Inheritance Picker

In code view, you can see that FormsUsingTemplate form is derived from Template Form.

Public Class FormsUsingTemplate
      Inherits VisualInherit.frmTemplate

And if you see in design view, FormsUsingTemplate form, all the inherited items from base templates is shown with special icon on the Form Items. These cannot be edited in the inherited form. If you need to edit any visual appearance of the template, then you need to edit in Template form which will be automatically reflected in derived form.

So, now you can add all required controls in the derived form, and if required, one can even override some of the methods in the base form by manually changing the code, modifiers and also methods depending on your requirement. In the sample application, I just shadowed the button click events in the derived form.

Private Shadows Sub butSubmit_Click(ByVal sender _
  As System.Object, ByVal e As System.EventArgs) Handles butSubmit.Click

  Dim msg As String
  msg = "Name :" & txtName.Text & " " &_
        "Age :" & " " & txtAge.Text & " " &_
        "Salary :" & txtSalary.Text
End Sub


Visual Inheritance helps in cutting down the development time, and also, just like inheritance in classes as language feature, inheritance can be used in forms designing as well.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Chandra Hundigam
United States United States
Chandra Hundigam has Master degree in Computer Application, Microsoft Certified Professional and Software Architect. He's significantly involved in enterprise application development and distributed object oriented system development using Microsoft .Net, Sun Java/J2EE technology to serve global giants in the Media, Finance, Mortgage and Software Industries.Presently working as Independent Software Consultant for a US-based company.His areas of interests are in emerging Technologies.

You may also be interested in...


Comments and Discussions

Questioninheritance restrictions Pin
kaimn_ryu10-May-12 2:55
memberkaimn_ryu10-May-12 2:55 
AnswerRe: inheritance restrictions Pin
tyler.durden4043-Sep-14 3:11
membertyler.durden4043-Sep-14 3:11 
Generaldatabase help Pin
faisalrana14-Nov-07 8:40
memberfaisalrana14-Nov-07 8:40 
GeneralRe: database help Pin
Paszt17-Oct-08 12:43
memberPaszt17-Oct-08 12:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171016.2 | Last Updated 14 May 2004
Article Copyright 2004 by Chandra Hundigam
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid