Tag Archives: drawline

Draw a Line on a Picturebox Control in VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
 

The source code snip below will draw a line and be persisted onto a picturebox control using Visual Basic.NET and Higher including VB 2008 and 2010.

'Draws a line on picturebox control
'
'Put a picturebox on the form named pic
Dim bit As Bitmap = New Bitmap(pic.Width, pic.Height)

Dim g As Graphics = Graphics.FromImage(bit)

Dim myPen As Pen = New Pen(Color.Blue, 3)

g.DrawLine(myPen, 0, 0, pic.Width, pic.Height)

pic.Image = bit