Draw line VB2005

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
 
H

Herfried K. Wagner [MVP]

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.
 
A

Armin Zingler

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
 
M

Matt

DrawLinePoint has to handle the form/control's paint event. Otherwise,
it won't display.
 
T

thomasp

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top