Diagonal Lines

Craig

Well-known member
Joined
Oct 15, 2005
Messages
110
Location
United Kingdom
Programming Experience
Beginner
This may be a very obvious question, is it possible to draw a diagonal line onto a form :confused:

Any help would be appreciated.
 
Yes, of course it's possible. You would do something like this in the forms on paint event.

e.graphics.drawline(50,50,300,300)

where the first two 50's are the starting point of your line on the x,y axis and the last two numbers represent the end point of the line on the x,y axis.
 
This error occurs

Overload resolution failed because no accessible 'DrawLine' accepts this number of arguments.
I used this to test it.

VB.NET:
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        e.Graphics.DrawLine(50, 50, 300, 300)
    End Sub
 
That was just an example of how to use it, you also need a pen object with which to draw your line. Either of the following two methods are what you need..

VB.NET:
e.graphics.drawline(new pen(color.black),30,30,500,500)

or

VB.NET:
dim MyPen as New Pen(color.black)
e.graphics.drawline(MyPen,30,30,500,500)
 
Back
Top