Beginning Visual Basic: A Step by Step Computer Programming Tutorial by Philip Conrod & Lou Tylee

Beginning Visual Basic: A Step by Step Computer Programming Tutorial by Philip Conrod & Lou Tylee

Author:Philip Conrod & Lou Tylee [Conrod, Philip]
Language: eng
Format: azw3
ISBN: 9781937161675
Publisher: Kidware Software LLC
Published: 2017-06-25T04:00:00+00:00


Graphics Objects

You need to tell Visual Basic that you will be using graphics methods with the panel control. To do this, you convert the panel control to something called a graphics object. Graphics objects provide the “surface” for graphics methods. Creating a graphics object requires two simple steps. We first declare the object using the standard Dim statement. If we name our graphics object MyGraphics, the form is:

Dim MyGraphics As Graphics

This declaration is placed in the general declarations area of the code window, along with our usual variable declarations. Once declared, the object is created using the CreateGraphics method:

MyGraphics = ControlName.CreateGraphics()

where ControlName is the name of the control hosting the graphics object (in our work, the Name property of the panel control). We will create this object in the form Load event of our projects.

Once a graphics object is created, all graphics methods are applied to this newly formed object. Hence, to apply a graphics method named GraphicsMethod to the MyGraphics object, use:

MyGraphics.GraphicsMethod(Arguments)

where Arguments are any needed arguments, or information needed by the graphics method.

There are two important graphics methods we introduce now. First, after all of your hard work drawing in a graphics object, there are times you will want to erase or clear the object. This is done with the Clear method:

MyGraphics.Clear(Color)

This statement will clear a graphics object (MyGraphics) and fill it with the specified Color. We will look further at colors next. The usual color argument for clearing a graphics object is the background color of the host control (ControlName), or:

MyGraphics.Clear(ControlName.BackColor)

Once you are done drawing to an object and need it no longer, it should be properly disposed to clear up system resources. To do this with our example graphics object, use the Dispose method:

MyGraphics.Dispose()

This statement is usually placed in the form FormClosing event procedure.

Our drawing will require colors and objects called pens, so let’s take a look at those concepts. Doesn’t it make sense we need pens to do some drawing?



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.