Drawing Circle and Squares - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to draw circles, squares and rectangles in Visual Basic .NET

Draw a Circle

The following code will draw a circle as in the following picture:

draw a circle in visual basic .net

Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
     Using Brush1 As New SolidBrush(Color.Blue)
          e.Graphics.FillEllipse(Brush1, 20, 20, 200, 200)
     End Using
     Using Pen1 As New Pen(Color.Red, 10)
          e.Graphics.DrawEllipse(Pen1, 20, 20, 200, 200)
     End Using
End Sub

Square or Rectangle:

draw a square or rectangle in visual basic

Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
     Dim square As New Rectangle(20, 20, 200, 200)
     Using Brush1 As New SolidBrush(Color.Blue)
          e.Graphics.FillRectangle(Brush1, square)
     End Using
End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.