目前我正在使用我在网上找到的这个 vb.net 代码,在下面将文本添加到表单中。有没有办法同时滚动多个文本?因此,对于我的数组,我将 Item2 放在 Item1 的正下方,依此类推,具体取决于数组中有多少项?我希望每个新项目都滚动到下一个项目的正下方。
Option Strict Off 'Strict has to be off for the font
Public Class Form1
Dim sItems() As String = {"Item1", "Item2", "Item3", "Item4"}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For index As Integer = 0 To sItems.Length - 1
animateText(sItems(index), Button1.Location.Y - 50, Button1.Location.Y - 50, Button1.Location.X)
Next
End Sub
Dim label As New Label
Dim maxHeight As Integer
Dim colour As Integer = 255
Public Sub animateText(ByVal text As String, ByVal lowerBounds As Integer, ByVal upperBounds As Integer, ByVal xPos As Integer)
maxHeight = upperBounds
label.Text = text
label.TextAlign = ContentAlignment.MiddleCenter
label.Location = New Point(xPos, lowerBounds)
label.Font = New Font(Font.Bold, 20)
label.AutoSize = True
Me.Controls.Add(label)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
label.Location = New Point(label.Location.X, label.Location.Y - 20) 'here's where you set the speed
If label.Location.Y = maxHeight Then
Timer1.Enabled = False
Me.Controls.Remove(label)
End If
End Sub
End Class