The following is the code that executes on the click of button1. My problem is that my line is not drawing correctly. I have tested the output of the values that points the line in the correct direction. They are coming out correct. However, when the line draws, at an angle the angle is going in the wrong direction.
i.e. a 45 degree angle is drawing at an angle of 305
Any help is greatly appreciated.
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog()
Dim MyValue() As String
x1 = 300
y1 = 300
ofd.InitialDirectory = "c:\"
ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Using sr As New System.IO.StreamReader(ofd.FileName)
Do
MyValue = sr.ReadLine.Split
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
length = Convert.ToDouble(MyValue(0))
angle = Convert.ToDouble(MyValue(1))
y = angle * (Math.PI / 180)
x2 = x1 + length
y2 = y1 + ((length) * (Math.Sin(y)))
tmr.Enabled = True
formGraphics.DrawLine(myPen, Convert.ToInt32(x1), Convert.ToInt32(y1), Convert.ToInt32(x2), Convert.ToInt32(y2))
TextBoxX.Text = Convert.ToString(y1)
TextBoxY.Text = Convert.ToString(y2)
TextBoxAngle.Text = MyValue(1)
x1 = x2
y1 = y2
If sr.EndOfStream Then
tmr.Enabled = False
End If
Try
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Click okay to try another file.")
End Try
Loop Until sr.EndOfStream
End Using
End If
End Sub
