Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse the PolyPolygon API function to quickly draw a series of polygons
Keywordspolygon, draw
CategoriesGraphics
 

When the form loads, it fills a two-dimensional POINTAPI array with the points used by a series of polygons. It also fills the counts array with the number of points in each polygon. It then calls the PolyPolygon API function to draw all the polygons at once. Note that this function recognizes Visual Basic's normal drawing properties: FillStyle, FillColor, ForeColor, DrawWidth, etc.

 
Private Sub Form_Load()
Const NUM_POLYGONS As Integer = 3

Dim pts(1 To 11) As POINTAPI
Dim counts(1 To NUM_POLYGONS) As Long
Dim i As Integer

    ' Triangle.
    pts(1).x = 5
    pts(1).y = 5
    pts(2).x = 50
    pts(2).y = 30
    pts(3).x = 15
    pts(3).y = 60
    counts(1) = 3   ' 3 points in the triangle.

    ' Rectangle.
    pts(4).x = 60
    pts(4).y = 10
    pts(5).x = 140
    pts(5).y = 10
    pts(6).x = 140
    pts(6).y = 70
    pts(7).x = 60
    pts(7).y = 70
    counts(2) = 4   ' 4 points in the rectangle.

    ' Trapezoid.
    pts(8).x = 50
    pts(8).y = 80
    pts(9).x = 10
    pts(9).y = 140
    pts(10).x = 160
    pts(10).y = 140
    pts(11).x = 90
    pts(11).y = 80
    counts(3) = 4   ' 4 points in the trapezoid.

    picCanvas.AutoRedraw = True
    picCanvas.FillStyle = vbFSSolid
    picCanvas.FillColor = vbGreen
    picCanvas.ForeColor = vbBlue
    picCanvas.DrawWidth = 2

    PolyPolygon picCanvas.hdc, pts(1), _
        counts(1), NUM_POLYGONS
End Sub
 
For more information on graphics programming in Visual Basic, see my book Visual Basic Graphics Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated