make the line "bounce"?

evocube

Member
Joined
Apr 26, 2009
Messages
9
Programming Experience
1-3
Ok I have a program that draws a line at a user defined angle based on moveable picture box.
It works fine but how do I make the line "bounce" at the correct angle?
Also is this the best way to do this or is there a better way??

VB.NET:
 Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        ' Draw line in picture box at radian angle

        Dim myPen As New System.Drawing.Pen(Color.Black)
        Dim formGraphics As System.Drawing.Graphics
        Dim degree As String

        Dim childposition As Point
        Dim parentposition As Point = Me.PointToClient(PictureBox1.PointToScreen(childposition))
        Dim cx1 As New Integer
        Dim cy1 As New Integer

        Dim depth As Double = PictureBox1.Height
        If angletxt.Text = 90 Then

            degree = 90 * (Math.PI / 180)
        ElseIf angletxt.Text > 90 Then
            MessageBox.Show("Must Be Lower then 90 Degrees", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            Return
        Else : degree = (90 - angletxt.Text) * (Math.PI / 180)

        End If


        Dim hypol As Integer = Math.Cos(degree) * depth
        Dim adj As Integer = 1 / Math.Tan(degree) * depth
        
        Dim r2p As Integer = PictureBox2.Right
        Dim b2p As Integer = PictureBox2.Bottom
       
        formGraphics = PictureBox1.CreateGraphics()
        cx1 = r2p + adj
        cy1 = childposition.Y + depth

        '-13 to compensate for edge of pictbox2
        formGraphics.DrawLine(myPen, r2p - 13, childposition.Y, cx1 - 13, cy1)
 
Back
Top