1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Visual Inheritance Using VB .NET Standard - Part 1
More on Keeping Your Money Away From Microsoft !

I'm a serious advocate of paying as little as possible for the programming tools you need. As part of this mission, I have long recommended that you score a fully licensed copy of VB .NET Standard Edition - and a book - by buying the the Microsoft Press Learning Edition for less than a hundred dollars. The complete Visual Studio is going to set you back $600 or $700 - Minimum! And whaddayaget? C#? Gimmeabreak! You can read more about this money saving option HERE.

Before jumping into the solution, thanks to Gerry for suggesting changes to this article that (hopefully) makes it easier to understand and use. If you like it now, Gerry deserves the credit!

One big problem with VB.NET Standard is that you can't create class libraries! They left it out of this version. That means that you can't do the great things that can be done by creating your own DLL's, including creating a DLL's containing forms. In the case of visual inheritance, this means Standard Edition only lets you use visual inheritance inside of one project.

To make this point more clear, here's a view of the output types that can be added to a solution using Standard Edition. If you compare this to a full edition, you'll see what's missing.

No Class Library

A full version of Visual Studio provides an option to create class libraries as an output type in addition to the ones in the red circle. One of the most important reasons that you might want to do this is to implement what Microsoft calls, Visual Inheritance. This article shows you how to get around this limitation. You might want to create class libraries for a lot of other reasons too. This article will show you a basic technique to get you started, but only discusses the specific technique of visual inheritance.

Before I go any further, let me caution you that the web ... and the bookstores ... are full of misinformation on this subject. Even some Microsoft pages are just plain wrong. (Although the example I remember did have a footnoted caution that it was based on a beta version of .NET.) Part of the problem is that much of what is actually going on is that "hidden under the cover" part of the Visual Studio. And part of the problem is that there are a number of ways to approach this. (In fact, a very helpful reader provided a new one in a later article that you can read here.) Most articles just cover one part of the problem and leave you to assume that it's the only one. I'm going to try to cover the whole range here ... mainly because that's the only way to really understand it.

This article shows you what you can do with the "out of the box" capabilites of VB.NET Standard Edition. If you're left thinking that visual inheritance isn't very useful after reading it, you're right! That's why they charge more for the full version! The main purpose for this article is to introduce some concepts that you need to understand. Part II (and the idea contributed by reader Elijah Taylor) show you how to gain back the capabilities left out of the Standard Edition.

As Guru Karl Moore has said in one of the better articles about visual inheritance, this technique doesn't make much sense when you first look at it. One of Karl Moore's best books is reviewed HERE.

Here's how visual inheritance is intended to be used:

Suppose you have a standard form that you want to use frequently across a project or even throughout your company in VB .NET projects. It might have carefully formatted graphics, a standard set of buttons, or a text box with a standard company disclaimer. The whole idea is that there are common elements in a form that you don't want to have to code over and over every time you use them. Repeating the code for this form in every project is certainly a waste of time ... not to mention that you can introduce bugs because it might not be quite right in every copy.

What you need is to be able to import that form into your projects as an object. That's Visual Inheritance.

The solution is to to compile your form as a DLL and then add it to your project as an Inherited Form. VB.NET standard does this just fine if you already have such a DLL. But it won't let you create one.

VB.NET Standard will let you add an inherited form to the same Solution because you can 'Build' the Form and that does everything that you need for a single Solution. This is the part that doesn't make sense because it's just not very useful. (For example ... The downloadable example in Matthew MacDonald's book, User Interfaces in VB .NET illustrates this limited technique even though the text suggests more. The reason is that there is no DLL in the downloaded example.)

Here's a whirlwind description of how to use visual inheritance in the Standard Edition.

Create a new VB .NET project. Add a few buttons or other controls to a Form so you can recognize it. Then select Build Solution from the menu. After this is done, Add a new Inherited Form to the Project.

Add Inherited Form

You should be able to select the first Form from the Inherited Form Picker and add a new form based on it to your project. This is basically a copy of the first form.

Inherited Form Picker

Visual Studio adds Glyphs to the image to let you know that these components are inherited, not actually in this form.

Inherited Form

Adding an inherited forms to your project this way might be more trouble than just doing two independent forms. If you had to put a whole bunch of very similar forms into one Solution, it could be a real time saver. And it doesn't help at all if you want to provide forms for other projects. To do that, you need a "fix" for the missing component in VB.NET Standard: the lack of a class library - that is, DLL - output.

Part 2 of this article shows you how to save about $600 on the cost of a complete Visual Studio package by duplicating the ability to create a class library with software that comes free from Microsoft.

©2017 About.com. All rights reserved.