393
Chapter 16
Inheriting Forms and Creating
Base Classes
After completing this chapter, you will be able to:
n Use the Inheritance Picker to incorporate existing forms in your projects.
n Create your own base classes with custom properties and methods.
n Derive new classes from base classes by using the Inherits statement.
An important skill for virtually all professional software developers today is the ability
to understand and utilize object-oriented programming (OOP) techniques. The changes
associated with OOP have been gaining momentum in recent versions of Microsoft Visual
Basic, including features that support inheritance, a mechanism that allows one class to
acquire the interface and behavior characteristics of another class.
Inheritance in Visual Basic 2010 is facilitated by both the Visual Basic language and tools within
the Integrated Development Environment (IDE). What this means is that you can build one
form in the development environment and pass on its characteristics and functionality to other
forms. In addition, you can build your own classes and inherit properties, methods, and events
from them.
In this chapter, you’ll experiment with both types of inheritance. You’ll learn how to integrate
existing forms into your projects by using the Inheritance Picker dialog box that is part of
Microsoft Visual Studio 2010, and you’ll learn how to create your own classes and derive new
ones from them by using the Inherits statement. With these skills, you’ll be able to utilize many
of the forms and coding routines you’ve already developed, making Visual Basic programming
a faster and more flexible endeavor. These improvements will help you design compelling user
interfaces rapidly and will extend the work that you have done in other programming projects.
Inheriting a Form by Using the Inheritance Picker
In OOP syntax, inheritance means having one class receive the objects, properties,
methods, and other attributes of another class. As I mentioned in the section “Adding
New Forms to a Program” in Chapter 14, “Managing Windows Forms and Controls
at Run Time,” Visual Basic goes through this process routinely when it creates a new
form in the development environment. The first form in a project (Form1) relies on the
Table of Contents
Inheriting Forms and Creating Base Classes................... 393
Inheriting a Form by Using the Inheritance Picker....................... 393
Creating Your Own Base Classes...................................... 399
Adding a New Class to Your Project.............................. 401
One Step Further: Inheriting a Base Class.............................. 408
Chapter 16 Quick Reference.......................................... 412