Name: Anonymous 2010-12-16 10:23
What did I do wrong? It seems like it works to me.
Imports System.Math
Class LineLengthWindow
Dim xDistance1 As Double
Dim yDistance1 As Double
Dim xDistance2 As Double
Dim yDistance2 As Double
Dim first_test As Boolean = False
Dim myLine As New Line()
Public Sub length_line(ByVal x, ByVal y)
Dim legnth As Double = Math.Sqrt(x ^ 2 + y ^ 2)
lengthOutputLabel.Content = legnth.ToString
End Sub
Private Sub lineCanvas_MouseLeftButtonDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim mousePosition As Point = e.GetPosition(lineCanvas)
'Grab mouse XY position on left mouse button down click
If first_test = False Then
xDistance1 = mousePosition.X
yDistance1 = mousePosition.Y
first_test = True
ElseIf first_test = True Then
xDistance2 = mousePosition.X
yDistance2 = mousePosition.Y
End If
End Sub
Private Sub lineCanvas_MouseLeftButtonUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim mousePosition As Point = e.GetPosition(lineCanvas)
If first_test = True Then 'to make sure the user clicked twice and to draw on the second mouse up
'draw the line code starts here
myLine.Stroke = Brushes.Black
myLine.X1 = xDistance1
myLine.X2 = mousePosition.X
myLine.Y1 = yDistance1
myLine.Y2 = mousePosition.Y
myLine.HorizontalAlignment = HorizontalAlignment.Left
myLine.VerticalAlignment = VerticalAlignment.Center
myLine.StrokeThickness = 2
lineCanvas.Children.Add(myLine)
'ends here
'pass the coordinates to the method to calculate the line length
length_line((xDistance1 + xDistance2), (yDistance1 + yDistance2))
End If
End Sub
End Class
Imports System.Math
Class LineLengthWindow
Dim xDistance1 As Double
Dim yDistance1 As Double
Dim xDistance2 As Double
Dim yDistance2 As Double
Dim first_test As Boolean = False
Dim myLine As New Line()
Public Sub length_line(ByVal x, ByVal y)
Dim legnth As Double = Math.Sqrt(x ^ 2 + y ^ 2)
lengthOutputLabel.Content = legnth.ToString
End Sub
Private Sub lineCanvas_MouseLeftButtonDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim mousePosition As Point = e.GetPosition(lineCanvas)
'Grab mouse XY position on left mouse button down click
If first_test = False Then
xDistance1 = mousePosition.X
yDistance1 = mousePosition.Y
first_test = True
ElseIf first_test = True Then
xDistance2 = mousePosition.X
yDistance2 = mousePosition.Y
End If
End Sub
Private Sub lineCanvas_MouseLeftButtonUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim mousePosition As Point = e.GetPosition(lineCanvas)
If first_test = True Then 'to make sure the user clicked twice and to draw on the second mouse up
'draw the line code starts here
myLine.Stroke = Brushes.Black
myLine.X1 = xDistance1
myLine.X2 = mousePosition.X
myLine.Y1 = yDistance1
myLine.Y2 = mousePosition.Y
myLine.HorizontalAlignment = HorizontalAlignment.Left
myLine.VerticalAlignment = VerticalAlignment.Center
myLine.StrokeThickness = 2
lineCanvas.Children.Add(myLine)
'ends here
'pass the coordinates to the method to calculate the line length
length_line((xDistance1 + xDistance2), (yDistance1 + yDistance2))
End If
End Sub
End Class