Turn a Textbox or Label Into a Marquee

Turn a Textbox or Label Into a Marquee

Sometimes you need to display information longer than the biggest textbox or label control you can have onscreen. I’ve written a routine that displays a textbox’s or label’s contents in marquee style, with the text moving from right to left. Animate your controls by adding a timer to the form and setting its Interval property to 250 (to update the display four times per second). On each timer tick, pass the control you want to animate to the ShiftChars routine. This routine works by reading the control’s contents, shifting the first character to the end, and reassigning the contents:

 lPrivate Sub Timer1_Timer()	Call ShiftChars(Text1)	Call ShiftChars(Label1)End SubPrivate Sub ShiftChars(ctl As Control)	Dim Buffer As String	Select Case TypeName(ctl)		Case "TextBox", "Label"			' Rely on default property to accept/return contents.			Buffer = ctl			If Len(Buffer) > 1 Then				ctl = Mid$(Buffer, 2) & Left$(Buffer, 1)			End If	End SelectEnd Sub

For a more natural display, make sure your text strings have a trailing space character.

See also  Is Machine Learning Automating Creativity in Graphic Design?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist