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
 
 
 
 
 
 
TitleDemonstrate the Graphics object's filling methods in VB .NET
DescriptionThis example shows how to demonstrate the Graphics object's filling methods in VB .NET.
Keywordsfill, filling, fill area, FillPath, FillPie, FillPolygon, FillRectangle, FillRectangles, FillClosedCurve, FillEllipse
CategoriesGraphics, VB.NET
 
This program demonstrates the Graphics object's filling methods: FillPath, FillPie, FillPolygon, FillRectangle, FillRectangles, FillClosedCurve, and FillEllipse.
 
Imports System.Drawing.Drawing2D
...
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim pts() As Point

    ' Draw a path.
    ' Make the path.
    Dim graphics_path As New GraphicsPath
    graphics_path.AddLine(10, 40, 60, 40)
    graphics_path.AddEllipse(60, 30, 30, 20)
    e.Graphics.FillPath(Brushes.Red, graphics_path)
    e.Graphics.DrawPath(Pens.Black, graphics_path)

    ' Draw an ellipse and a pie slice on it.
    Dim rect As New Rectangle(10, 70, 40, 30)
    e.Graphics.DrawEllipse(Pens.White, rect)
    e.Graphics.FillPie(Brushes.Green, rect, 10, 45)
    e.Graphics.DrawPie(Pens.Black, rect, 10, 45)

    ' Draw a polygon.
    pts = New Point() { _
        New Point(10, 100), _
        New Point(80, 140), _
        New Point(80, 90), _
        New Point(10, 130) _
    }
    e.Graphics.FillPolygon(Brushes.Yellow, pts)
    e.Graphics.DrawPolygon(Pens.Black, pts)

    ' Draw a rectangle.
    rect = New Rectangle(10, 150, 50, 20)
    e.Graphics.FillRectangle(Brushes.Brown, rect)
    e.Graphics.DrawRectangle(Pens.Black, rect)

    ' Draw some rectangles.
    Dim rects() As Rectangle = { _
        New Rectangle(10, 190, 20, 30), _
        New Rectangle(20, 200, 40, 10), _
        New Rectangle(40, 180, 10, 50) _
    }
    e.Graphics.FillRectangles(Brushes.Aquamarine, rects)
    e.Graphics.DrawRectangles(Pens.Black, rects)

    ' Draw a closed curve.
    pts = New Point() { _
        New Point(150, 150), _
        New Point(200, 200), _
        New Point(180, 150), _
        New Point(130, 200) _
    }
    e.Graphics.FillClosedCurve(Brushes.BlueViolet, pts)
    e.Graphics.DrawClosedCurve(Pens.Yellow, pts)

    ' Draw an ellipse.
    rect = New Rectangle(230, 10, 50, 30)
    e.Graphics.FillEllipse(Brushes.DarkMagenta, rect)
    e.Graphics.DrawEllipse(Pens.White, rect)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated