Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have five panels, panel1 is at location(0, 0), panel2 is at location(816, 0)off the screen, panel3 is at location(1632, 0)off the screen, and so on. I would like to know how to scroll from right to left and left to right displaying the contents of each panel and the panel. If I scroll from panel1 to panel2, I have a choice to scroll back to panel1 or scroll to panel3. The scrolling effect that I am trying to get is similar to CloneDVD2.
Posted
Comments
Fredrik Bornander 5-Apr-11 16:16pm    
Is this using winforms or WPF?
rspercy65 5-Apr-11 18:32pm    
WinForms

1 solution

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) :

VB
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
 
Share this answer
 
Comments
rspercy65 6-Apr-11 8:54am    
Thanks for your solution Fredrik, Your name will be added to the code in my comments. I had to change some of the code to work with my app, but all-in-all, it works great!.
Once again, Thanx alot.
rspercy60
Fredrik Bornander 6-Apr-11 9:18am    
Glad I could help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900