Professional Documents
Culture Documents
Lec 11 and 12
Lec 11 and 12
Introduction
• Before you can draw anything on a form, you need to create the
Graphics object in Visual Basic .
• A graphics object is created using the CreateGraphics() method.
• You can create a graphics object that draws to the form itself or a
control.
Example
Creating a Pen
Drawing a Line
• In this section, we will show you how to draw a straight line on the
Form.
• First of all, launch Visual basic. In the start up page, drag a button into
the form.
• Double click on the button and key in the next code.
Drawing a Line
Drawing a Line
• Method 1
• The first is to draw a rectangle directly using
the DrawRectangle method by specifying its upper-left corner’s
coordinate and its width and height. The method of the Graphics
object to draw the rectangle is DrawRectangle.The syntax is:.
myGrapphics.DrawRectangle(myPen, X, Y, width, height)
Drawing a Rectangle
Drawing a Rectangle
Drawing a Rectangle
myPen.DashStyle = Drawing.Drawing2D.DashStyle.Dot
End Sub
Drawing a Rectangle
Drawing a
Rectangle
Drawing a
Rectangle
Drawing Text
Drawing Text
Drawing Text