|
|
Title | Draw rectangles, ellipses, lines, arcs, pie slices, and text in VB.NET |
Description | This 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. |
Keywords | rectangle, ellipse, line, arc, pie, pie slice, DrawRectangle, DrawEllipse, DrawLine, DrawArc, DrawPie, DrawString, VB.NET |
Categories | Graphics, 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.
|
|
|
|
|
|