how to draw arrowline 
Author Message
 how to draw arrowline

>Hi, all, I need to draw arrowlines at run time.  Does
>anybody know how to do that?

Option Explicit

Private Sub DrawArrow(ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As
Long, ByVal y2 As Long, ByVal colr As OLE_COLOR)
Dim x3 As Long, x4 As Long
Dim y3 As Long, y4 As Long
Dim xs As Long, ys As Long
Dim theta As Single
Dim L As Long
Const pi = 3.14159

'line between coords x1, y1 and x2, y2
'want a line from x2, y2 of length L, in direction 45 deg clockwise
from orig line direction
'direction of orig line is theta:
L = 180

xs = x2 - x1
ys = y2 - y1
If xs <> 0 Then
  theta = Atn(ys / xs)
  If xs < 0 Then
    theta = theta + pi
  End If
  If ys < 0 Then
    theta = 3 * pi / 2 '90
   theta = pi / 2  '270
  End If
End If
'rotate direction
theta = theta - 4 * pi / 5 ' - 3 * pi / 4
'find end of one side of arrow:
x3 = L * Cos(theta) + x2
y3 = L * Sin(theta) + y2
'rotate other way for other arrow line
theta = theta + 8 * pi / 5 '- pi / 2
x4 = L * Cos(theta) + x2
y4 = L * Sin(theta) + y2
'draw the lines
Line (x1, y1)-(x2, y2), colr
Line (x2, y2)-(x3, y3), colr
Line (x2, y2)-(x4, y4), colr

End Sub

Private Sub Form_Load()
Me.DrawMode = 7
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Static OldX As Single
Static OldY As Single

If Button Then Exit Sub

If OldX Then
    DrawArrow Me.Width / 2, Me.Height / 2, OldX, OldY, &HFFFFFF
End If
DrawArrow Me.Width / 2, Me.Height / 2, X, Y, &HFFFFFF
OldX = X
OldY = Y
End Sub

Jim Deutch

Sat, 12 Feb 2005 23:53:57 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Drawing functions(formulas) to draw graphics Like Fxtools.vbx

2. Where can I find a good Owner Drawn Combo and Owner Drawn TextBox

3. put drawing object inside another drawing object

4. Are there any Text drawing functions that can identify and draw URL Highlighted Text

5. Weird Drawing exeption: type initializer for "System.Drawing.SafeNativeMethods"

6. How do I draw a line that can draw OVER a control or container?

7. Where can I find a site with good Owner Drawn Combo and Owner Drawn TextBox ?

8. Drawing Arrow on a form

9. Draw rectangle on form at runtime

10. drawing on a form or pictureboxs in access?

11. Two Layer Drawing Window

12. Can I draw a circle?


Powered by phpBB® Forum Software