问题描述
我有五个面板,panel1位于屏幕外的位置(0,0),panel2位于屏幕外的位置(816,0),panel3位于屏幕外的位置(1632,0),依此类推.我想知道如何从右向左滚动和从左向右滚动以显示每个面板和面板的内容.如果我从panel1滚动到panel2,则可以选择向后滚动到panel1或滚动到panel3.我试图获得的滚动效果类似于CloneDVD2.
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.
推荐答案
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
希望这会有所帮助,
弗雷德里克·博纳德(Fredrik Bornander)
Hope this helps,
Fredrik Bornander
这篇关于如何从一个面板平滑滚动到下一个面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!