SlideShare a Scribd company logo
Visual Basic
Lines and Shapes
2
Objectives
 Explain the coordinate system used to
position graphical objects on a form.
 Draw lines from code.
 Draw boxes and rectangles from code.
 Draw circles and ellipses from code.
3
Objectives (continued)
 Draw polygrams.
 Create images made up of multiple
objects drawn on a form.
4
Drawing Objects Using Code
 Visual Basic .NET provides a single
Graphic object with a large number of
methods that allow a program to draw
on a form.
 A Graphics object is a general-purpose
drawing surface that may be used with
a number of graphical tools in Visual
Studio .NET.
5
Understanding Coordinates
 In order to begin working with drawing
objects, you must first understand the
coordinate system on a form.
 The top-left point on a form has an X
coordinate of zero and a Y coordinate of
zero.
 To use the DrawLine method, you need to think
in terms of X and Y rather than top and left.
 The combination of the X and Y value is
called a Point.
6
Understanding Pens and
Brushes
 After specifying the location of an
object, you will also have to specify a
Pen or Brush to use to draw the object.
 A pen is used to draw lines or the outline
of a shape.
 A brush is used to fill in shapes or to draw
text.
7
Using the DrawLine Method
 To use the DrawLine method, you
must specify the endpoints of the line
you want to draw and the pen you
want to use to draw the line.
 You can also create a Pen inside the
DrawLine statement.
8
Drawing Rectangles and
Boxes
 Rectangles and boxes can be drawn in two
different ways:
 The DrawRectangle method uses a Pen object
and is used to draw the outline of a rectangle.
 The FillRectangle method uses a Brush object
and is used to draw a rectangle that is filled in.
 The rectangle is created with an X and Y
location for its top-left corner and two other
parameters that will specify the width and
height properties.
9
Drawing Circles and Ellipses
 Like rectangles, circles and ellipses can
either be drawn as outlines or as filled
objects.
 The parameters for the DrawEllipse method
are a Pen object, the location of the ellipse,
and the width and height of the ellipse.
 The FillEllipse method uses the same
location and size parameters, but uses a
Brush object in place of a Pen object.
10
Drawing Polygons
 A polygon is any shape with three or
more sides.
 The DrawPolygon method takes a Pen
as its first parameter.
 The second parameter is an array of
points.
 The array has one element less than
the number of sides in the polygon.
11
Locating the Mouse
 The MouseDown event returns a number of
useful pieces of information.
 It returns the location on the form where the
mouse was pointing when the mouse button was
pressed.
 This variable, ”e,” has an X and Y coordinate
and holds the location where the mouse was
clicked.
 This will allow your program to draw
wherever the user wishes to draw.
12
Clearing the Form
 The form can be cleared in two ways:
 Parts of the form may be cleared by
drawing new shapes over existing
shapes.
 Another way is to use the Clear method
of the Graphics objects.
13
Summary
 You can use the DrawLine method to draw a
line on a form using Visual Basic. NET code.
 There are two ways to draw most shapes
on a form. A Draw method creates an outline
drawing of the object. The Fill method
creates an object that is filled with a color
specified by a brush color.
 A Pen object is created with a color and may
also have a line specified for it.
14
Summary (continued)
 Rectangles (including squares) are created
using the DrawRectangle and FillRectangle
methods. Rectangles are objects that can
be declared with a starting point and width
and height. Once they are declared,
rectangle objects can be used to draw both
rectangles and ellipses.
 Ellipses (including circles) are created using
the DrawEllipse and FillEllipse methods.
15
Summary (continued)
 Once you have drawn a line, rectangle,
ellipse, or other shape with a graphic
method, you cannot manipulate it. The
graphic methods draw directly on a form.
 The MouseDown event returns information
about the location of the mouse and the
button that was used to click on the mouse.
 The Clear method of the Graphics object is
used to erase the whole form.
16
Summary (continued)
 Distance and position on a form is mea-
sured using coordinates. The top-left corner
of a form has the coordinates (0, 0). All
coordinates are positive. As you move
toward the bottom of a form, the X-coordi-
nate value increases. As you move toward
the right of a form, the Y-coordinate value
increases.

More Related Content

PPT
Identitas trigonometri
PDF
Obj. 43 3-D Representation
PDF
1291 fa13 assign2_cube_drawings
PDF
1291 fa13 assign4_digitizing_folded_models
PPTX
Machine parts orthographic projections
PPTX
GeoGebra 10
DOCX
Creating beats logo
PDF
1291 fa13 assign5_unroll_and_lasercut
Identitas trigonometri
Obj. 43 3-D Representation
1291 fa13 assign2_cube_drawings
1291 fa13 assign4_digitizing_folded_models
Machine parts orthographic projections
GeoGebra 10
Creating beats logo
1291 fa13 assign5_unroll_and_lasercut

What's hot (19)

PDF
Obj. 50 3-D Representation
PDF
PDF
L1 slides
PPTX
Geogebra 9
PDF
Plan601 e session 4 demo
DOCX
G6 m3-c-lesson 17-s
PDF
Dm week01 linreg.handout
PPT
Inequalties Of Combined Functions2[1]
PPT
GeoGebra Talk - A basic introduction
PPTX
Efficient Estimation for High Similarities using Odd Sketches
PPTX
Geogebra 8
PPT
Cap.7
PPT
Algebra 1, 5 3
PDF
Plan601 e session 1 demo 20151005
PPTX
computer graphics-C/C++-dancingdollcode
PDF
1291 fa13 assign6_folded_model_paneling
PPT
Inequalties Of Combined Functions2[1]
DOCX
Task 3 geometry
Obj. 50 3-D Representation
L1 slides
Geogebra 9
Plan601 e session 4 demo
G6 m3-c-lesson 17-s
Dm week01 linreg.handout
Inequalties Of Combined Functions2[1]
GeoGebra Talk - A basic introduction
Efficient Estimation for High Similarities using Odd Sketches
Geogebra 8
Cap.7
Algebra 1, 5 3
Plan601 e session 1 demo 20151005
computer graphics-C/C++-dancingdollcode
1291 fa13 assign6_folded_model_paneling
Inequalties Of Combined Functions2[1]
Task 3 geometry
Ad

Similar to VB Lines and Shapes (20)

PPT
Chapter 13
PPT
DrawingVb.net : using graphics in visual basic
PDF
Intake 37 6
PDF
Delphi L06 GDI Drawing
PDF
C# Summer course - Lecture 2
PPTX
Objects and classes in Visual Basic
PPT
Chap2.pptgsosnsvsjsnc sounds ksngdid idvdmg dhdo an the that was how
PDF
Intake 38 6
PPT
VB Tutotrial and introduction and methods
PPT
Graphics
PPTX
Intro to visual studio 2008
PPT
visual programming GDI presentation powerpoint
PPT
Visual programming Chapter 3: GUI (Graphical User Interface)
PPTX
ch 3 of C# programming in advanced programming
PPT
Introduction to Visual Studio 2022-OS.ppt
PDF
Visual Basic IDE Introduction
PDF
Visual Basic IDE Intro.pdf
PPT
Chapter 06
PPTX
2.3 exploring shapes
PPT
Csphtp1 02
Chapter 13
DrawingVb.net : using graphics in visual basic
Intake 37 6
Delphi L06 GDI Drawing
C# Summer course - Lecture 2
Objects and classes in Visual Basic
Chap2.pptgsosnsvsjsnc sounds ksngdid idvdmg dhdo an the that was how
Intake 38 6
VB Tutotrial and introduction and methods
Graphics
Intro to visual studio 2008
visual programming GDI presentation powerpoint
Visual programming Chapter 3: GUI (Graphical User Interface)
ch 3 of C# programming in advanced programming
Introduction to Visual Studio 2022-OS.ppt
Visual Basic IDE Introduction
Visual Basic IDE Intro.pdf
Chapter 06
2.3 exploring shapes
Csphtp1 02
Ad

More from obrienduke (8)

PPT
VB Multiple Forms
PPT
M14 overview
PPTX
Mod 12
PPTX
Module 7
PPTX
Unit 4 bugs and debugging
PPT
Module 3 GUI Design
PPTX
Arrays in java
PPT
Nested loops
VB Multiple Forms
M14 overview
Mod 12
Module 7
Unit 4 bugs and debugging
Module 3 GUI Design
Arrays in java
Nested loops

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Classroom Observation Tools for Teachers
PDF
Complications of Minimal Access Surgery at WLH
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Lesson notes of climatology university.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Anesthesia in Laparoscopic Surgery in India
Classroom Observation Tools for Teachers
Complications of Minimal Access Surgery at WLH
TR - Agricultural Crops Production NC III.pdf
VCE English Exam - Section C Student Revision Booklet
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Lesson notes of climatology university.
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Computing-Curriculum for Schools in Ghana
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

VB Lines and Shapes

  • 2. 2 Objectives  Explain the coordinate system used to position graphical objects on a form.  Draw lines from code.  Draw boxes and rectangles from code.  Draw circles and ellipses from code.
  • 3. 3 Objectives (continued)  Draw polygrams.  Create images made up of multiple objects drawn on a form.
  • 4. 4 Drawing Objects Using Code  Visual Basic .NET provides a single Graphic object with a large number of methods that allow a program to draw on a form.  A Graphics object is a general-purpose drawing surface that may be used with a number of graphical tools in Visual Studio .NET.
  • 5. 5 Understanding Coordinates  In order to begin working with drawing objects, you must first understand the coordinate system on a form.  The top-left point on a form has an X coordinate of zero and a Y coordinate of zero.  To use the DrawLine method, you need to think in terms of X and Y rather than top and left.  The combination of the X and Y value is called a Point.
  • 6. 6 Understanding Pens and Brushes  After specifying the location of an object, you will also have to specify a Pen or Brush to use to draw the object.  A pen is used to draw lines or the outline of a shape.  A brush is used to fill in shapes or to draw text.
  • 7. 7 Using the DrawLine Method  To use the DrawLine method, you must specify the endpoints of the line you want to draw and the pen you want to use to draw the line.  You can also create a Pen inside the DrawLine statement.
  • 8. 8 Drawing Rectangles and Boxes  Rectangles and boxes can be drawn in two different ways:  The DrawRectangle method uses a Pen object and is used to draw the outline of a rectangle.  The FillRectangle method uses a Brush object and is used to draw a rectangle that is filled in.  The rectangle is created with an X and Y location for its top-left corner and two other parameters that will specify the width and height properties.
  • 9. 9 Drawing Circles and Ellipses  Like rectangles, circles and ellipses can either be drawn as outlines or as filled objects.  The parameters for the DrawEllipse method are a Pen object, the location of the ellipse, and the width and height of the ellipse.  The FillEllipse method uses the same location and size parameters, but uses a Brush object in place of a Pen object.
  • 10. 10 Drawing Polygons  A polygon is any shape with three or more sides.  The DrawPolygon method takes a Pen as its first parameter.  The second parameter is an array of points.  The array has one element less than the number of sides in the polygon.
  • 11. 11 Locating the Mouse  The MouseDown event returns a number of useful pieces of information.  It returns the location on the form where the mouse was pointing when the mouse button was pressed.  This variable, ”e,” has an X and Y coordinate and holds the location where the mouse was clicked.  This will allow your program to draw wherever the user wishes to draw.
  • 12. 12 Clearing the Form  The form can be cleared in two ways:  Parts of the form may be cleared by drawing new shapes over existing shapes.  Another way is to use the Clear method of the Graphics objects.
  • 13. 13 Summary  You can use the DrawLine method to draw a line on a form using Visual Basic. NET code.  There are two ways to draw most shapes on a form. A Draw method creates an outline drawing of the object. The Fill method creates an object that is filled with a color specified by a brush color.  A Pen object is created with a color and may also have a line specified for it.
  • 14. 14 Summary (continued)  Rectangles (including squares) are created using the DrawRectangle and FillRectangle methods. Rectangles are objects that can be declared with a starting point and width and height. Once they are declared, rectangle objects can be used to draw both rectangles and ellipses.  Ellipses (including circles) are created using the DrawEllipse and FillEllipse methods.
  • 15. 15 Summary (continued)  Once you have drawn a line, rectangle, ellipse, or other shape with a graphic method, you cannot manipulate it. The graphic methods draw directly on a form.  The MouseDown event returns information about the location of the mouse and the button that was used to click on the mouse.  The Clear method of the Graphics object is used to erase the whole form.
  • 16. 16 Summary (continued)  Distance and position on a form is mea- sured using coordinates. The top-left corner of a form has the coordinates (0, 0). All coordinates are positive. As you move toward the bottom of a form, the X-coordi- nate value increases. As you move toward the right of a form, the Y-coordinate value increases.