Dim MoveRight As Boolean
Dim MoveRight As Boolean








            Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                                        PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                        Timer2.Enabled = True
                                        Timer1.Enabled = False
                                    End Sub







             Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                                    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage 



              End Sub





             Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly2.gif")
                                    Timer3.Enabled = True
                                    Timer2.Enabled = False
                                End Sub



                                Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly3.gif")
                                    Timer4.Enabled = True
                                    Timer3.Enabled = False
                                End Sub



                                Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly4.gif")
                                    Timer5.Enabled = True
                                    Timer4.Enabled = False
                                End Sub



                                Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly5.gif")
                                    Timer6.Enabled = True
                                    Timer5.Enabled = False
                                End Sub



                                Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly6.gif")
                                    Timer7.Enabled = True
                                    Timer6.Enabled = False
                                End Sub

                                Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly5.gif")
                                    Timer8.Enabled = True
                                    Timer7.Enabled = False
                                End Sub



                                Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly4.gif")
                                    Timer9.Enabled = True
                                    Timer8.Enabled = False
                                End Sub



                                Private Sub Timer9_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer9.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly3.gif")
                                    Timer10.Enabled = True
                                    Timer9.Enabled = False
                                End Sub



                                Private Sub Timer10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly2.gif")
                                    Timer11.Enabled = True
                                    Timer10.Enabled = False
                                End Sub



                                Private Sub Timer11_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer11.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                    Timer12.Enabled = True
                                    Timer11.Enabled = False
                                End Sub





                            Private Sub Timer12_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer12.Tick
                                PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                Timer1.Enabled = True
                                Timer12.Enabled = False
                            End Sub



                            Private Sub Timer13_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer13.Tick
                                If MoveRight = True Then
                                    PictureBox1.Left += 10
                                Else
                                    PictureBox1.Left -= 10
                                End If
                                If Moveup = True Then
                                    PictureBox1.Top -= 10
                                Else
                                    PictureBox1.Top += 10
                                End If
                                If PictureBox1.Left <= Me.PictureBox1.SizeMode Then
                                    MoveRight = True
                                End If
                                If PictureBox1.Left + PictureBox1.Width >= Me.PictureBox1.SizeMode Then
                                    MoveRight = False
                                End If
                                If PictureBox1.Top <= Me.PictureBox1.Top Then
                                    Moveup = False
                                End If
                                If PictureBox1.Top + PictureBox1.Height >= Me.PictureBox1.Bottom Then
                                    Moveup = True
                                End If
                            End Sub
                        End Class











            Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                                        PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                        Timer2.Enabled = True
                                        Timer1.Enabled = False
                                    End Sub







             Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                                    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage 



              End Sub





             Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly2.gif")
                                    Timer3.Enabled = True
                                    Timer2.Enabled = False
                                End Sub



                                Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly3.gif")
                                    Timer4.Enabled = True
                                    Timer3.Enabled = False
                                End Sub



                                Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly4.gif")
                                    Timer5.Enabled = True
                                    Timer4.Enabled = False
                                End Sub



                                Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly5.gif")
                                    Timer6.Enabled = True
                                    Timer5.Enabled = False
                                End Sub



                                Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly6.gif")
                                    Timer7.Enabled = True
                                    Timer6.Enabled = False
                                End Sub

                                Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly5.gif")
                                    Timer8.Enabled = True
                                    Timer7.Enabled = False
                                End Sub



                                Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly4.gif")
                                    Timer9.Enabled = True
                                    Timer8.Enabled = False
                                End Sub



                                Private Sub Timer9_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer9.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly3.gif")
                                    Timer10.Enabled = True
                                    Timer9.Enabled = False
                                End Sub



                                Private Sub Timer10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly2.gif")
                                    Timer11.Enabled = True
                                    Timer10.Enabled = False
                                End Sub



                                Private Sub Timer11_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer11.Tick
                                    PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                    Timer12.Enabled = True
                                    Timer11.Enabled = False
                                End Sub





                            Private Sub Timer12_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer12.Tick
                                PictureBox1.Image = Image.FromFile("C:\Users\Adrian\Documents\but\Butterfly1.gif")
                                Timer1.Enabled = True
                                Timer12.Enabled = False
                            End Sub



                            Private Sub Timer13_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer13.Tick
                                If MoveRight = True Then
                                    PictureBox1.Left += 10
                                Else
                                    PictureBox1.Left -= 10
                                End If
                                If Moveup = True Then
                                    PictureBox1.Top -= 10
                                Else
                                    PictureBox1.Top += 10
                                End If
                                If PictureBox1.Left <= Me.PictureBox1.SizeMode Then
                                    MoveRight = True
                                End If
                                If PictureBox1.Left + PictureBox1.Width >= Me.PictureBox1.SizeMode Then
                                    MoveRight = False
                                End If
                                If PictureBox1.Top <= Me.PictureBox1.Top Then
                                    Moveup = False
                                End If
                                If PictureBox1.Top + PictureBox1.Height >= Me.PictureBox1.Bottom Then
                                    Moveup = True
                                End If
                            End Sub
                        End Class

Please explain exactly what you are trying to do. Whatever your code is doing is not clear. I can tell that you want the picture to move but I need to know how you want it to move.

i want a code that would make my butter flymove without using the keyboard.

the if statements are used for the moving of the picture. the rest of the program just makes the butter fly move its wings.

The following code bounces the picturebox left and right between two limits. You can modify this to move the butterfly in random directions.

Public Class Form1

    Private increment As Integer = -1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Timer1.Interval = 10
        Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

        pbx1.Location = New Point(pbx1.Location.X + increment, pbx1.Location.Y)

        'reverse direction if we reached a limit

        If pbx1.Location.X = 10 Or pbx1.Location.X = 400 Then
            increment = -increment
        End If

    End Sub

End Class

I don't know why you need so many timers. As far as I can tell you only need one to animate the wings (cycle through a series of images) and one to move the image around. You could have a separate Sub which does nothing but calculate the next position based on some pseudo-random algorithm. If you wanted to get fancy you could create a butterfly class (object) and encapsulate the code and properties. That way it would be easy to generate multiple butterflies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.