Solved

Draw arrow heads on lines in VB6

Posted on 2002-07-30
5
1,507 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 115
using web browser with BING 40 131
vbModal 12 57
Need Nag Screen for Reboot if system up time is over 14 days 12 61
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 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