I want to draw three straight lines on a form.

Can you tell me if the following code is correct:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim Line1 As System.Drawing.Graphics
        Dim PenLine As New System.Drawing.Pen(System.Drawing.Color.Black)
        Line1 = Me.CreateGraphics
        Line1.DrawLine(PenLine, 0, 129, 529, 129)
        Line1.DrawLine(PenLine, 0, 180, 529, 180)
        Line1.DrawLine(PenLine, 0, 190, 529, 190)
    End Sub

Can I use only one variable (Line1) to draw three straight lines?
Is this the right way to do it?

It's almost right.

Don't create a graphics object here. Its a waste. Use the graphics object
in the paint event args.

Other than that your good to go.

e.graphics.DrawLine(PenLine, 0, 129, 529, 129)       
 e.graphics.DrawLine(PenLine, 0, 180, 529, 180)       
 e.graphics.DrawLine(PenLine, 0, 190, 529, 190

'clean up your resources.

Edited 6 Years Ago by Unhnd_Exception: n/a

This question has already been answered. Start a new discussion instead.