Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Feb 24, 2000

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:
 
l
Private Sub Timer1_Timer()
	Call ShiftChars(Text1)
	Call ShiftChars(Label1)
End Sub
Private 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 Select
End Sub
For a more natural display, make sure your text strings have a trailing space character.
Rafat Sarosh
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date