Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 16 Inheriting Forms and Creating Base Classes 399



  1. Click OK.


The inherited form runs the event procedure that it inherited from Form1, and the
event procedure displays the following message:


  1. Click OK, and then click the Click Me! button.


Form2 displays the inherited form message.
What this demonstrates is that Form2 (the inherited form) has its own characteristics
(a new Click Me! button and an enlarged size). Form2 also uses two buttons (OK
and Cancel) that were inherited from Form1 and contain the code from Form1, as well
as the exact visual representation of the buttons. This means that you can redeploy
the user interface and code features that you have previously created without
cumbersome cutting and pasting. In other words, you’ve encountered one of the main
benefits of OOP—reusing and extending the functionality of existing forms, program
code, and projects. You’ve also learned to use the Visual Studio Inheritance Picker
dialog box, which offers a handy way to select objects you want to reuse.


  1. Click OK to close the message box, and then click Close on the form to end the
    program.
    The program stops, and the IDE returns.


Creating Your Own Base Classes


The Inheritance Picker managed the inheritance process in the previous exercise by creating
a new class in your project named Form2. To build the Form2 class, the Inheritance Picker
established a link between the Form1 class in the My Form Inheritance project and the new
form. Here’s what the new Form2 class looks like in the Code Editor:
Free download pdf