如何在vb.net中使用Marquee类文本?

时间:2011-03-11 22:41:02

标签: vb.net winforms marquee

有没有办法让Windows窗体中的文本像HTML中的选框标记中的文本一样滚动?

2 个答案:

答案 0 :(得分:1)

您可以使用计时器和几个变量来帮助您这样做。这样的事情可以做......

'Class-level variables.
Private m_intMarqueeCounter As Integer = 1
Private m_bolMarqueeIncrementUp As Boolean = True

Private Sub YourMarqueeTimer_Tick()

   'You can decide what number is best for your app.
   If m_intMarqueeCounter = 10 Then

      m_bolMarqueeIncrementUp = False

   End If

   If m_intMarqueeCounter = 0 Then

      m_bolMarqueeIncrementUp = True

   End If

   Dim intX As Integer
   For intX = 0 to m_intMarqueeCounter

      frmYourForm.Text = " " & "Your Title"

   Next

   If m_bolMarqueeIncrementUp Then

      m_intMarqueeCounter += 1

   Else

      m_intMarqueeCounter -= 1

   End If

End Sub

答案 1 :(得分:0)

Const marqueeText As String = "The quick brown fox...   "
Dim sb As New System.Text.StringBuilder
Dim direction As Boolean = False 'true = left to right, false = right to left

Private Sub Timer1_Tick(sender As System.Object, _
                        e As System.EventArgs) Handles Timer1.Tick

    If sb.Length = 0 Then sb.Append(marqueeText)
    If direction Then
        sb.Insert(0, sb(sb.Length - 1))
        sb.Remove(sb.Length - 1, 1)
    Else
        sb.Append(sb(0))
        sb.Remove(0, 1)
    End If
    Me.Text = sb.ToString
End Sub