Chapter 15 Quick Reference

Chapter 15 Quick Reference


Do this

Create lines or shapes on a form

Use methods in the System.Drawing.Graphics namespace. For example, the following program statements draw an ellipse on the form:

Dim GraphicsFun As System.Drawing.Graphics
 GraphicsFun = Me.CreateGraphics
 Dim PenColor As New System.Drawing.Pen _
 GraphicsFun.DrawEllipse(PenColor, 10, _
  120, 200, 160)

Create lines or shapes that persist on the form during window redraws

Place the graphics methods in the Paint event procedure for the form.

Move an object on a form

Relocate the object by using the Location property, the New keyword, and the Point structure. For example:

PictureBox1.Location = New Point(300, 200)

Animate an object

Use a timer event procedure to modify the Left, Top, or Location properties for an object on the form. The timer's Interval property controls animation speed.

Expand or shrink an object at run time

Change the object's Height property or Width property.

Change the transparency of a form

Change the Opacity property.

Chapter 16

Inheriting Forms and Creating Base Classes

After completing this chapter, you will be able to:

  • Use the Inheritance Picker to incorporate existing forms in your projects.

  • Create your own base classes with custom properties and methods.

  • 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. Although Microsoft Visual Basic 6 offers several object-oriented programming features, experts say that it lags behind the “true” OOP languages, such as Microsoft Visual C++, because it lacks inheritance, a mechanism that allows one class to acquire the interface and behavior characteristics of another class.

Beginning with Microsoft Visual Basic .NET 2002, the Visual Basic language and IDE have supported inheritance, which means that you can build one form in the development environment and pass its characteristics and functionality on 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 2005, 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.

Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005

If you're experienced with Visual Basic 6, you'll notice some new features in Microsoft Visual Basic 2005, including the following:

  • You can inherit forms within the Visual Studio IDE by using the Inheritance Picker dialog box.

  • Classes are now defined between the Public Class and End Class keywords.

  • Several user-defined classes can now be stored in a single source file. (In Visual Basic 6, each new class has to be stored in its own file.)

  • You can add properties to classes by using a new syntax, first introduced in Visual Basic .NET 2002.

  • The Inherits keyword allows a new derived class to inherit the interface and behaviors of an existing class.