0

Hello...

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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ak24
1

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.
 PenLine.dispose

Edited by Unhnd_Exception: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.