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
 
 
 
 
 
TitleDraw rectangles, ellipses, lines, arcs, pie slices, and text in VB.NET
DescriptionThis example shows how to draw rectangles, ellipses, lines, arcs, and pie slices in VB.NET. This example demonstrates the Graphics object's DrawRectangle, DrawEllipse, DrawLine, DrawArc, DrawPie, and DrawString methods.
Keywordsrectangle, ellipse, line, arc, pie, pie slice, DrawRectangle, DrawEllipse, DrawLine, DrawArc, DrawPie, DrawString, VB.NET
CategoriesGraphics, VB.NET
 
This example demonstrates the Graphics object's DrawRectangle, DrawEllipse, DrawLine, DrawArc, DrawPie, and DrawString methods.
 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim x As Integer = 10
    Dim y As Integer = 10
    Dim wid As Integer = 150
    Dim hgt As Integer = 75
    e.Graphics.SmoothingMode = _
        Drawing2D.SmoothingMode.AntiAlias
    e.Graphics.DrawRectangle(Pens.Black, x, y, wid, hgt)
    y += hgt + 10
    e.Graphics.DrawEllipse(Pens.Black, x, y, wid, hgt)
    y += hgt + 10
    e.Graphics.DrawLine(Pens.Black, x, y, x + wid, y + hgt)

    y = 10
    x += wid + 10
    e.Graphics.DrawArc(Pens.Black, x, y, wid, hgt, -30, 270)
    y += hgt + 10
    e.Graphics.DrawPie(Pens.Black, x, y, wid, hgt, -30, 270)
    y += hgt + 10

    Dim big_font As New Font("Comic Sans MS", 60, _
        FontStyle.Bold, GraphicsUnit.Pixel)
    e.Graphics.TextRenderingHint = _
        TextRenderingHint.AntiAliasGridFit
    e.Graphics.DrawString("Hello!", big_font, _
        Brushes.Black, x, y)
End Sub
 
Note that the Graphics object also has corresponding Fill methods: FillRectangle, FillEllipse, FillLine, FillArc, and FillPie. These take exactly the same arguments as their Draw counterparts except they use a Brush instead of a Pen.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated