VB.NET tutorial-VB.NET draw lines

VB.NET draw lines

To draw a single line on the form, the DrawLine(Pen, Point1,Point2) can be used. With multiple lines you can use the DawLines(Pen, Array_Of_Points) method. To draw lines with different colors, you need to specify each color with Pen argument.

Example: Draw lines 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 point objects
        Dim pt As New Point(50, 50)
        Dim pt1 As New Point(300, 50)
        Dim pt2 As New Point(200, 70)
        Dim pt3 As New Point(50, 170)
        Dim pt4 As New Point(300, 170)
        Dim pt5 As New Point(200, 70)
        'Array of points
        Dim pArra() As Point = {pt2, pt3, pt4, pt5}
        'Draw a line
        e.Graphics.DrawLine(Pens.Orange, pt, pt1)
        'Draw multiple lines
        e.Graphics.DrawLines(Pens.Blue, pArra)
    End Sub
End Class

VB example code to draw lines

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.