Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

412 Part III Designing the User Interface


Chapter 16 Quick Reference


To Do This
Inherit an existing
form’s interface
and functionality

Click the Add New Item command on the Project menu, click the Inherited
Form template, specify a name for the inherited form, and then click Add.
Use the Inheritance Picker to select the form you want to inherit, and then
click OK.
Note that to be eligible for inheritance, base forms must be compiled as
.exe or .dll files. If you want to inherit a form that isn’t a component in the
current project, the form must be compiled as a .dll file.
Customize an
inherited form

Add Toolbox controls to the form, and set property settings. Note that
you won’t be able to set the properties of inherited objects on the form.
These objects are identified by small icons and are inactive.
Create your own
base classes

Click the Add Class command on the Project menu, specify the class name,
and then click Add. Define the class in a class module by using program code.
Hide declared
variables in a class

Use the Private keyword to hide class variables from other programmers
who examine your class. For example:
Private Name1 As String
Create a new
property in the class

Define a public property procedure in the class. For example:
Public Property FirstName() As String
Get
Return Name1
End Get
Set(ByVal value As String)
Name1 = value
End Set
End Property
Note that the first line shown in this example (containing the Property
statement) is all that you may need to enter if you are creating a new property
with few custom settings. In other words, Visual Studio 2010 automatically
recognizes the Property keyword when you enter it and uses the new
auto-implemented properties feature to create a basic property definition for
you. However, in this chapter, I have shown the complete Get and Set syntax
because it is useful in many real-world coding scenarios.
Create a new method
in the class

Define a Sub or Function procedure in the class. For example:
Public Function Age(ByVal Birthday As Date) As Integer
Return Int(Now.Subtract(Birthday).Days / 365.25)
End Function
Declare an object
variable to use the
class

Use the Dim and New keywords, a variable name, and the user-defined class
in a program statement. For example:
Dim Employee As New Person
Free download pdf