Solved

Draw arrow heads on lines in VB6

Posted on 2002-07-30
5
1,535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

696 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