Solved

Draw arrow heads on lines in VB6

Posted on 2002-07-30
5
1,490 Views
Last Modified: 2012-05-04
Hello everyone

I am creating an application that has a drawing element, rather like Visio.

It allows lines to connect various objects on screen. These lines can be at any angle (not just the compass points).

I need to be able to draw an arrow head at one end of the line. I suppose I could calculate the line angle and then calculate the points of the arrow triangle from this.

Is there an easier way? Perhaps a Win API function will automatically ad an arrow head to a line?

Thanks

0
Comment
Question by:DapperDan
5 Comments
 
LVL 20

Expert Comment

by:hes
ID: 7188950
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 7189009
Here is a way to draw an arrow on a picture box or form.  The object you are drawing on is marked out in x, y coordinates for the purpose of drawing:

To test this sample, create a new project, add a command button and a picture box to the default form and then copy this code into the form's code window.  You may have to resize the picture box to see the results.

Option Explicit

Private Sub Command1_Click()
  Picture1.AutoRedraw = True
  Call sDrawArrow(1000, 1000, 500, 500, Picture1)
  Call sDrawArrow(100, 100, 1000, 2000, Picture1)
  Call sDrawArrow(200, 200, 3000, 1500, Picture1)
  Call sDrawArrow(100, 300, 100, 3000, Picture1)
  Call sDrawArrow(500, 3000, 500, 300, Picture1)
 
End Sub

Public Sub sDrawArrow(x1 As Long, y1 As Long, x2 As Long, y2 As Long, picbox As PictureBox)
  Const ASize = 300
  Dim sngAngLine As Single
  Dim intRev As Integer
  Dim xL As Long, yL As Long, xR As Long, yR As Long
  picbox.Line (x1, y1)-(x2, y2)
 
  If x2 >= x1 Then
      intRev = -1
  Else
      intRev = 1
  End If
 
'    x2,y2 will be head of arrow.

'    angle of line
  If x2 - x1 <> 0 Then
      sngAngLine = Atn((y2 - y1) / (x2 - x1))
  Else
      If y2 > y1 Then
          sngAngLine = 3.1415 / 2
      Else
          sngAngLine = 1.5 * 3.1415
      End If
  End If
 
  Debug.Print sngAngLine
  xL = intRev * (Cos(sngAngLine - (3.1415 / 8))) * ASize + x2
  yL = intRev * (Sin(sngAngLine - (3.1415 / 8))) * ASize + y2
  xR = intRev * (Cos(sngAngLine + (3.1415 / 8))) * ASize + x2
  yR = intRev * (Sin(sngAngLine + (3.1415 / 8))) * ASize + y2
 
  Debug.Print xL, yL, xR, yR
  picbox.Line (x2, y2)-(xL, yL)
  picbox.Line (x2, y2)-(xR, yR)

End Sub
0
 

Author Comment

by:DapperDan
ID: 7190231
I'll have a look at both of these, thanks.
0
 

Author Comment

by:DapperDan
ID: 7195640
Thanks, both of you.

I used Paul's solution in the end, so I should probably give the points to him.
0
 

Expert Comment

by:akanelson
ID: 8316790
i'm looking for something like that.
can u send me what u did ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now