Solved

Draw arrow heads on lines in VB6

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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
Paint/Redraw window while dragging 16 86
Passing a Text Box name to a Sub 6 102
Added a column screws up code 5 69
how to loop through and process two columns in excel 8 51
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

749 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