Scrolling Text in VB.NET Window Form

W

Will Gillen

I need to have a "scrolling" text label or textbox at the bottom of my
window to show the URL of where a song is being played from. I want the
text to scroll on a single line from left to right in case the URL is longer
than the width of the textbox/text label.

Is there a native way to do this in VB.NET?
 
M

Mike McIntyre

Hi Will,

One technique is to use a Timer control and in its Tick handler manipulate a
string to create a scrolling effect e.g.

Private _NowPlaying As String = "This test will get scrolled."
Private Sub NowPlayingTimer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NowPlayingTimer.Tick
_NowPlaying = _NowPlaying.Substring(_NowPlaying.Length - 1, 1) &
_NowPlaying.Substring(0, _NowPlaying.Length - 1)
NowPlayingLabel.Text = _NowPlaying
End Sub

_NowPlaying is a String variable declared at the class level (a class member
field) that holds the string currently being displayed in a label named
NowPlayingLabel.

Each time the Timer's Tick event is handled the _NowPlaying string is
changed by pulling a character off one end of the string and placing at the
other end of the string.

_NowPlaying = _NowPlaying.Substring(_NowPlaying.Length - 1, 1) &
_NowPlaying.Substring(0, _NowPlaying.Length - 1)

After the modification the NowPlayLabel.Text is updated with the
modification.

NowPlayingLabel.Text = _NowPlaying

The end result is a scrolling text effect in the NowPlayingLabel.

Setting the Timer's Interval to 200 produces a nice scroll effect.

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
W

Will Gillen

Actually you were right on, it was me who did not phrase correctly.
Your answer was what I was looking for....

I tried your approach, and it does work, however, it is still a little
"jerky". I had thought about doing it that way, but was thinking there may
be something more "smooth" for the scrolling text... kind of like a
scrolling marquee in HTML...

I'll keep looking... If anyone knows of some control that does this, please
let me know. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top