Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 16 Inheriting Forms and Creating Base Classes 395


Now you’ll practice inheriting the form. The first step in this process is building, or
compiling, the project because you can inherit only from forms that are compiled into
.exe or .dll files. Each time the base form is recompiled, changes made to the base form
are passed to the derived (inherited) form.


  1. Click the Build My Form Inheritance command on the Build menu.


Visual Basic compiles your project and creates an .exe file.


  1. Click the Add New Item command on the Project menu, and then click the Windows
    Forms category on the left side of the dialog box and the Inherited Form template in
    the middle of the dialog box.
    The Add New Item dialog box looks as shown in the following screen shot:


Note Visual Basic 2010 Express does not include the Inherited Form template. If you are
looking for justification to upgrade to Visual Studio Professional, this may provide some.
(In general, Professional and the other full versions of Visual Studio provide a number
of additional templates that are useful .) At this point, you may want to simply review
the sample project that I have included on the Practice Files CD and examine the code.
However there is a work-around that you can attempt to create an inherited form^ manually.
To try it, add a Windows Form named Form2 .vb to your project instead of Inherited Form.
At the top of Solution Explorer, click the Show All Files toggle button. Expand Form2 .vb and
then open Form2 .Designer .vb. Change “Inherits System .Windows .Forms .Form” to “Inherits
My_Form_Inheritance .Form1 .” Click Save All, close Form2 .Designer .vb, and then click Show
All Files again to hide the advanced files. Since you performed the steps manually, you can
now skip to the next section, “Customize the Inherited Form .”
Free download pdf