0

** this is what i have so far, this should move to the top right corner, but it seems to be going on non-stop.
any help will be appreciated, if there was any inclarity please inform me, i will clarify.

**

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub
     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If Button1.Left = (Me.Width - Button1.Width) Then
            Timer1.Enabled = False
        Else
            Button1.Left += 10
            Button1.Top -= 10
        End If
    End Sub
2
Contributors
1
Reply
4
Views
2 Years
Discussion Span
Last Post by Reverend Jim
0

Your problem is that your position is falling between the cracks. For example, if your x coordinates vary like 53, 63, 73, etc. and you are checking for an exact limit such as x = 100 to stop then your timer will not stop because you pass by 100 without equalling it. Try something like

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If Button1.Right >= Me.Width Or Button1.Top <= 0 Then
        Timer1.Enabled = False
    Else
        Button1.Left += 10
        Button1.Top -= 10
        Me.Text = Button1.Left & "," & Button1.Top
    End If
End Sub

Play with the exact nunmbers to get the button to stop right at the edge.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.