Draw line VB2005

  • Thread starter Thread starter thomasp
  • Start date Start date
T

thomasp

I found the following code on MSDN to draw a line in VB2005.

Public Sub DrawLinePoint(ByVal e As PaintEventArgs)

' Create pen.
Dim blackPen As New Pen(Color.Black, 3)

' Create points that define line.
Dim point1 As New Point(100, 100)
Dim point2 As New Point(500, 100)

' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)

End Sub

This seems to be just what I need, but I can't figure out how to call the
sub. I want my code to determine the two points then have the sub draw the
line.

Call DrawLinePoint() don't work and I don't know what value to pass it. I
hope I am just missing something simple here.


Thanks,

Thomas
 
I found the following code on MSDN to draw a line in VB2005.

Public Sub DrawLinePoint(ByVal e As PaintEventArgs)

' Create pen.
Dim blackPen As New Pen(Color.Black, 3)

' Create points that define line.
Dim point1 As New Point(100, 100)
Dim point2 As New Point(500, 100)

' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)

End Sub

This seems to be just what I need, but I can't figure out how to call the
sub. I want my code to determine the two points then have the sub draw
the
line.

Call DrawLinePoint() don't work and I don't know what value to pass it. I
hope I am just missing something simple here.

Place the code in the form's or control's 'Paint' event handler or override
its 'OnPaint' method and perform the drawing there.
 
I found the following code on MSDN to draw a line in VB2005.

Public Sub DrawLinePoint(ByVal e As PaintEventArgs)

' Create pen.
Dim blackPen As New Pen(Color.Black, 3)

' Create points that define line.
Dim point1 As New Point(100, 100)
Dim point2 As New Point(500, 100)

' Draw line to screen.
e.Graphics.DrawLine(blackPen, point1, point2)

End Sub

This seems to be just what I need, but I can't figure out how to
call the sub. I want my code to determine the two points then have
the sub draw the line.

Call DrawLinePoint() don't work and I don't know what value to pass
it. I hope I am just missing something simple here.


'PaintEventArgs' are passed to the Paint event. Handle the event of the
object you want to draw on and pass the argument called 'e' to the sub.


Armin
 
I have got it working. I just have to write some code that will only paint
it when I want it. I don't want the line painted everytime the form is
loaded or refreshed.

Thanks,

Thomas
 
Back
Top