VB.NET tutorial-VB.NET draw rectangles


VB.NET draw rectangles

In this page, you will learn to draw a single and multiple rectangles on the current form. To draw a single rectangle on the form, the DrawRectangle(Pen, Rectangle_Obj) can be used. With multiple rectangles you can use the DrawRectangles(Pen, Array_Of_Rectangle_Objs) method.

Example: Draw rectangles on the current form


Public Class Form1
    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       
     'Create rectangle objects
        Dim rt As New Rectangle(100, 100, 100, 100)
        Dim rt1 As New Rectangle(250, 100, 100, 100)
        Dim rt2 As New Rectangle(400, 100, 100, 100)
        'Array of rectangle objects
        Dim arrRect() As Rectangle = {rt1, rt2}
        'Draw rectangles
        e.Graphics.DrawRectangle(Pens.Bisque, rt)
        e.Graphics.DrawRectangles(Pens.PaleGreen, arrRect)
 
    End Sub
End Class

VB example code to draw rectangles  




Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.