KnowDotNet Visual Organizer

Use Visual Inheritance to Standardize and Speed RAD

Article #1 in Series - RAD Tips

by Les Smith
Print this Article Discuss in Forums

Use Visual Inheritance to speed up and standardize Rapid Application Development.  This is the first in a series of articles designed to highlight new technologies that come with Visual Studio .NET and is designed to illustrate ways to standardize and enhance your ability to develop applications rapidly.  See the second article, which is on Custom Properties in Windows Forms.

Before launching into the meat of the article, I want to make a point regarding , "If you are not keeping up, you are falling behind!"  That seems rather obvious, but the fact is that new technologies are emerging and changing so rapidly that it is utterly impossible to stay on top of all of them, especially as it relates to .NET.  Furthermore, if you are not spending some quality time each week, reading, trying things, experimenting, etc., you are falling behind, whether you realize it or not.  For instance, I am studying for a certification test right now myself, and even if I never take or pass the test, I am learning new methodlogies, and finding things  in .NET that I never knew existed.  

So, let me urge you to set aside some time every week, in the midst of the battle, in which we all find ourselves, just to improve your knowledge and skills.  I know that your boss expects you to meet deadlines, but whether he or she realizes it or not, you must continue to improve your knowledge base and skill set, or you will not be able to continue to produce the kind of applications that your management expects.  In other words, you may be on the right track, but if you don't keep moving, you will get run over by the train of new technology that is racing down the track behind you.

Now, to the article at hand; for years, as a Visual Basic developer, I was not sure what all the hype regarding Inheritance was about.  Now, with the advent of .NET, I am seeing the time-saving and standardization features that Visual Inheritance makes available.  In this article, I will cover a simple template form that might be used for creating dialogs in an application.  For this application, I want to enforce uniformity in the appearance of the the dialogs, and I want to automatically set many of the properties so that other developers can create dialogs without having to take the time to set all of the properties that I have already set in the template dialog.

Figure 1 shows the template form (frmDialogTemplate) in the Windows Designer.  The following list shows the properties that I have set in this template form.

  • Icon Property set to my standard icon.

  • FormBorderStyle set to FixedSingle.

  • Maximize and Minimize Buttons set to False.

  • Set a base Text Value.>


Figure 1 - Creating the Standard Template Form.

Template Dialog


Now, I will create a new form from the frmDialogTemplate.  It will automatically have the appearance and characteristics of the template.  To do this, I right-click on the Project in the Solution Explorer, and choose Add Inherited Form.  When the Add New Item Dialog appears, I click on the Inherited Form Icon.  Next, I will name my new form as frmMyNewDialog.vb.  Finally, I click the OK button.

Since the new form is Inherited, the Inheritance Picker dialog will be displayed as shown in Figure 2.  Because I only have one form, from which to inherit, I click OK to add the new form to my project.  

Figure 2 - Inheritance Picker.

Inheritance Picker


Obviously, you can place code in the template form, that will be executed by the inherited form, but you will not see that code in the inherited form.  For example, the following code is in the the frmDialogTemplate Form Class, but you will not see it in the inherited form, frmMyNewDialog, yet Figure 3 shows the result of the inherited code being executed when the inherited form displays.

#Region " Event Handlers "
  
Private Sub frmDialogTemplate_Load(ByVal sender As Object, _
      
ByVal e As System.EventArgs) Handles MyBase.Load
      
Me.Text = "MyNewDialog - Testing"
  
End Sub
#End Region

Figure 3 - The Inherited Form Running.

Inherited Form Running


As you can see, the Text Property of the new form has been changed, but there is no code in it that affects the change.  The Text is changed by the base form code shown above.  You will also see that the new dialog has inherited all of the visual properties that I set in the frmDiallogTemplate.

This is a simple example of what you can and should begin to do with Visual Inheritance.  It not only saves me time, but allows me to force standardization of look and feel of my forms.

Top of Page

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing