Solved

Draw arrow heads on lines in VB6

Posted on 2002-07-30
5
1,481 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
Comment Utility
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
Comment Utility
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
Comment Utility
I'll have a look at both of these, thanks.
0
 

Author Comment

by:DapperDan
Comment Utility
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
Comment Utility
i'm looking for something like that.
can u send me what u did ?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now