Draw Line

pmusu

New member
Joined
Dec 31, 2005
Messages
4
Programming Experience
1-3
Hi,

I have an array which contains location points of 2 circles on screen.

I want to be able to draw a line with an arrow between the 2 circles.

How can i implement this.

So basically i have circles that among other attributes contain X and Y coordinates.

My idea is to implement a loop that finds the coordinates and draws the line with arrow.

This should not be difficult to implement however i do not know how to implement code of actually drawing the line.

Can anyone help?

Thanks in advance.
 
Hi, Assuming that you are accustom to using GDI+ and also that you have drawn your circles using GDI+ then drawing a line is no different. You can simply draw your line using...

e.Graphics.DrawLine(X1,Y1,X2,Y2)

if you coding inside a paint event, or.....

Dim G as graphics = me.creategraphics

G.DrawLine(X1,Y1,X2,Y2)

if you are not. You can even code your line into a GraphicsPath.Is this the answer you were looking for or would you like a more detailed description. If So can you explain exactly what you want to do, and how you would like ot do it.
 
Thanks

the first code was what i was looking for,

e.Graphics.DrawLine(X1,Y1,X2,Y2)

Sorry for simple question but i am new to VB.Net even though i know some programming.
 
Thanks for answer

One last thing, i have drawn the line.

What i need is to do is draw an arrow at the end of the line

like this

-->

with > = arrow

-- = line

This is code used to draw line getting coordinates from an array and connecting with a line the 2 circles together

Me.CreateGraphics.DrawLine(pen, (myarray(TextBox1.Text, 1)), (myarray(TextBox1.Text, 2)), (myarray(TextBox2.Text, 1)), (myarray(TextBox2.Text, 2)))

What i need is to add an arrow cap at the end of the line
Thanks in advance
 
This is called LineCaps and is an enumeration, and you set them for the pen objects StartCap and EndCap properties.
Example:
VB.NET:
dim p as new pen(color.black, 10)
p.endcap = drawing2d.linecap.arrowanchor
e.graphics.drawline(p, coords....)
p.dispose()
 
Thanks

Just to give something back here is the code. The code in red is what i changed. It works

Thanks to all again

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectarray(20, 20)

Dim p As New Pen(Color.Black, 5)
p.EndCap = Drawing2D.LineCap.ArrowAnchor


Me.CreateGraphics.DrawLine(p, (myarray(TextBox1.Text, 1)), (myarray(TextBox1.Text, 2)), (myarray(TextBox2.Text, 1)), (myarray(TextBox2.Text, 2)))
node1 = node1 + (+1)
connectarray(node1, 1) = (TextBox1.Text)
connectarray(node1, 2) = (TextBox2.Text)
MessageBox.Show(node1 & " " & connectarray(node1, 1) & " " & connectarray(node1, 2))
End Sub
 
Back
Top