I am trying to create a marque effect in a label using a timer. Can't remember exactly how to do it.
Thanks!:)
Printable View
I am trying to create a marque effect in a label using a timer. Can't remember exactly how to do it.
Thanks!:)
Hello. I'm sure someone knows how to do this :) I can sorta get it working but it's not perfect.
Speaking of not perfect this is what I came up with. It is based on you making the initial label caption the text plus spaces equal to the distance you want to scroll it. If you want do it without having to include the spaces in the caption when you start, you should determine how many characters the label can hold(not sure how do to this in code, but i am sure it can be done) then use the second code snippet I included. It's not the most graceful but it does work.
Code 1(timer set to 70 ms)
VB Code:
Private Sub Timer1_Timer() Label1.Caption = Right(Label1.Caption, 1) + Left(Label1.Caption, Len(Label1.Caption) - 1) End Sub
Code 2(timer set to 70 ms)
VB Code:
Private Sub Timer1_Timer() If Len(Label1.Caption) < maxtextlength Then Label1.caption = " " + Label1.Caption Else Label1.Caption = Right(Label1.Caption, 1) + Left(Label1.Caption, Len(Label1.Caption) - 1) End If End Sub
Yah man... nice try and thanks, but i'm looking for a perfect example. I can already half a$$ do it haha.:)
There is no perfect example. It's not like the control is designed to handle marquee. Anything you do is going to involve working around it. You could eliminate the label control all together and try to do it with pure API, but it is a matter of convenience.
Uhh yah.. there are perfect examples.. i've done it before. I just lost the code and can't find it on this site ATM.. But it can be perfectly and simply done.
I assume the difficulty you're having is that you want the text to move through a set width label, rather than just shift the .Left property of the label?
I use this when I need it (which is similar to Joey_k29's)VB Code:
Private Sub Timer1_Timer() 'To Use this, set the Timer Interval to about 250 Text1.Text = ScrollText(Text1.Text) 'Or Label1.Caption = ScrollText(Label1.Caption) End Sub Private Function ScrollText(MyText As String) As String 'Take the first char of a string and move it to the back. MyText = (Right$(MyText, Len(MyText) - 1)) & Left$(MyText, 1) ScrollText = MyText End Function
You can use a picturebox with a label on it.
Set picturebox.BorderStyle to none, and paste
this code in the timer event.
VB Code:
Private Sub Timer1_Timer() If Label1.Left + Label1.Width < 0 Then Label1.Left = Picture1.ScaleWidth Else Label1.Left = Label1.Left - 15 End If End Sub
This will keep the scrolling within the picturebox area.