how to put scrolling text on label ?

PRAISE PHS

Well-known member
Joined
Jun 2, 2011
Messages
58
Programming Experience
Beginner
Hi All, Please I have a timer on my window's app. I also dropped a label and docked it at d buttom of my window with some text on it. How do I code the app such that the text on the label would be scrolling from the right of my screen to the left and it repeats itself continuosly so long as the app is running. pls kindly help. Thanks.
 
Easiest way I would do this, is put a panel in place of the label on the form, then add a label to the panel and use a timer to simply move the label inside the panel. In the timer's tick even, simply teak the label's Left property and you can use the width property to know when the label is completely off the left side of the panel.
 
Here's an old thread of mine that does basically what JB suggests, except that it wraps the whole lot into a user control instead of using a Panel ad hoc.

Scrolling Text

I wondered whether that thread would show up in a web search so I searched for vb.net scrolling text label. I didn't see my thread in the first few pages at least but I did see LOADS of other results. That kinda suggests to me that you didn't bother looking at all before posting here. I certainly wouldn't discourage people from using forums like this as a resource but far too many people use them as their first option instead of looking for existing information first and then turning to forums when they can't find what they need or understand what they find.
 
Here is another [not perfect] solution, using GDI. It scrolls nicely but it's a little blunt... The label is autosize, but it works well when docked in a panel slightly less wide than the total text length. This is really crude, I made this a while ago and never bother to finish the edges off because I ended up doing something else. Looking at it now, it would probably be easier to use the same movement event but move the whole label inside the panel as JuggaloBrother stated.

Public Class MarqueeLabel
    Inherits Label

    Private WithEvents Timer As New Timer With {.Interval = 50}

    Private CurrentPosition As Integer = 0

    Public Sub New()
        MyBase.New()

        UseCompatibleTextRendering = True
        AutoEllipsis = False
        AutoSize = True

        SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)

        AddHandler Timer.Tick, AddressOf Timer_Tick
        Timer.Start()
    End Sub

    Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
        If CurrentPosition < - Width Then
            CurrentPosition = Width
        Else
            CurrentPosition -= 1
        End If

        Invalidate()
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        e.Graphics.TranslateTransform(CType(CurrentPosition, Double), 0)
        MyBase.OnPaint(e)
    End Sub

    Protected Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not Timer Is Nothing Then Timer.Dispose()
        End If

        Timer = Nothing
    End Sub
End Class
 
Last edited:
Thanks a lot all for your responses. I'm really grateful for your concerns.
@Jim...I understood your message and I'm really sorry if I have by anyway done anything wrong. Though, I actually did a lot of researches online before my post. Just that I was not getting what I actually wanted. I think this was as a result of the key words I was using for the searches. Once again, I'm deeply sorry and I look forward to learning more from this great forum. Thank you all.
 
Back
Top