Option Explicit
Private m_InDrawMode As Boolean
Private m_ActivateDrawmode As Boolean
Private mblnFirstLineDone As Boolean
Public avatar As String
Private m_Lines() As Line
Private Sub Command1_Click()
If (Not m_InDrawMode) Then _
m_ActivateDrawmode = Not m_ActivateDrawmode
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (m_ActivateDrawmode And Not m_InDrawMode) Then
'create a new line and initialise it at the current mouse pointer
If (mblnFirstLineDone) Then
ReDim Preserve m_Lines(UBound(m_Lines) + 1)
Else
mblnFirstLineDone = True
End If
Set m_Lines(UBound(m_Lines)) = Me.Controls.Add("VB.Line", "Line" & CStr(UBound(m_Lines)), Picture1)
With m_Lines(UBound(m_Lines))
.X1 = X
.X2 = X
.Y1 = Y
If (UBound(m_Lines)) Then
.Y2 = X + m_Lines(UBound(m_Lines) - 1).Y2 / m_Lines(UBound(m_Lines) - 1).X2
Else
.Y2 = Y
End If
.Visible = True
.BorderColor = &H80000002
End With
m_InDrawMode = True
End If
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If m_InDrawMode Then 'move the end point of the line
With m_Lines(UBound(m_Lines))
' If it is the first line, allow user to change angle
If (UBound(m_Lines) = 0) Then
.Y2 = Y
Else
' If it is a subsequent line, force the angle
' to be the same
With m_Lines(0) ' Slope is of 1st line
' y = mx + c
' m = (y2-y1)/(x2-x1) + c
' ... y = ((y2-y1)/(x2-x1))x + c
Dim m As Double, c As Double
m = ((.Y2 - .Y1) / (.X2 - .X1))
c = m_Lines(UBound(m_Lines)).Y1
' x1 = (X - x0)
m_Lines(UBound(m_Lines)).Y2 = _
(m * (X - m_Lines(UBound(m_Lines)).X1)) + c
End With
End If
.X2 = X
End With
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_InDrawMode = False
m_ActivateDrawmode = False
End Sub
Private Sub Form_Load()
ReDim m_Lines(0)
Me.ScaleMode = vbPixels
End Sub