我试图找出如何用非常长的字符串做一个新闻 - 自动收报机类型的循环。我的控件采用显示的字符串变量,因此我需要将变量更改为正确的序列。
我正在研究下面的一些东西,这种方法很有效,直到我到达字符串的末尾。
textVar = longstring.Substring(currentPos, maxStringLength)
但是一旦我到达终点并将其添加到开头,我不确定如何回到开头。有没有人看到任何简化此过程的控件或有关如何执行代码的建议?
currentPos是一个整数来表示字符串中的位置,而maxStringLength是一个变量,它具有我可以一次显示的字符数量。字符串将从数据库加载,长度将从5个字符开始变化。
关于如何到达那里的任何建议或指示都会很棒,或者如果有人找到了自由控制来做到这一点,它也是合适的。
添加一个Timer
控件到您的表单,并在属性或您的Enabled=True
Form
上设置load
。为其Tick
事件制作一个处理程序。现在添加一个Label
,然后添加一些行,如果你想。
这是Tick
的处理程序
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Interval = 1 'Sets the interval of the Timer speed
Label1.Left = Label1.Left - 3 'How much pixel will be deducted to the left of the control
If Label1.Left < 0 - Label1.Width Then 'Loops the strings back to right
Label1.Left = Width '^
End If
End Sub
.Interval - n
和.Left - n
都控制速度。
这对我来说太棒了。
全局变量:
dim TickerText as string
然后我从SQL查询中获取了自动收录器文本行,并通过数据表将其保存到TickerText变量中。
cmdstr = "SELECT TOP(1) MAX(ID) as LastID, Highlight FROM dbo.HighlightTable Group By Highlight"
Dim da1 As New SqlDataAdapter(cmdstr, con)
Dim dt1 As New DataTable
da1.Fill(dt1)
Dim dv1 As DataView = dt1.DefaultView
For Each rowview As DataRowView In dv1
TickerText = rowview(1)
Next
'Salesticker is my label on the main form
SalesTicker.Text = TickerText
'this statement starts the ticker out blank, so all text comes in from the right hand side of the screen
SalesTicker.Left = Width
然后我的计时器代码与上面使用的征服者相同。我只是将间隔改为35以减慢速度。它在循环中运行得很漂亮。