There's many ways of achieving this type of animation, below is a fairly naive solution that should work in most cases (this example assumes there's a form with two buttons,
prev and
next, and it will populate it with animated panels in the
Load
event) :
Public Class Form1
Private panels As IList(Of Panel) = New List(Of Panel)
Private currentIndex As Integer = 0
Private WithEvents animationTimer As Timer = New Timer()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
panels.Add(New Panel With {.BackColor = Color.Red, .Location = New Point(0, 0), .Size = New Size(200, 200)})
panels.Add(New Panel With {.BackColor = Color.Green, .Location = New Point(200, 0), .Size = New Size(200, 200)})
panels.Add(New Panel With {.BackColor = Color.Blue, .Location = New Point(400, 0), .Size = New Size(200, 200)})
panels.Add(New Panel With {.BackColor = Color.Yellow, .Location = New Point(600, 0), .Size = New Size(200, 200)})
For Each panel As Panel In panels
Controls.Add(panel)
Next
animationTimer.Interval = 50
animationTimer.Start()
End Sub
Private Sub AnimationTimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles animationTimer.Tick
If panels(currentIndex).Location.X <> 0 Then
Dim delta As Integer = panels(currentIndex).Location.X / 4.0
For Each panel As Panel In panels
panel.Location = New Point(panel.Location.X - delta, panel.Location.Y)
Next
End If
End Sub
Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousButton.Click
currentIndex = Math.Max(0, currentIndex - 1)
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
currentIndex = Math.Min(panels.Count - 1, currentIndex + 1)
End Sub
End Class
Hope this helps,
Fredrik Bornander