|
-
Aug 8th, 2002, 07:31 AM
#1
Thread Starter
PowerPoster
Using a timer to scroll text in a label
I am trying to create a marque effect in a label using a timer. Can't remember exactly how to do it.
Thanks!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 8th, 2002, 09:53 AM
#2
Thread Starter
PowerPoster
Hello. I'm sure someone knows how to do this I can sorta get it working but it's not perfect.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 8th, 2002, 10:31 AM
#3
Hyperactive Member
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
Last edited by Joey_k29; Aug 8th, 2002 at 10:37 AM.
-
Aug 8th, 2002, 10:49 AM
#4
Thread Starter
PowerPoster
Yah man... nice try and thanks, but i'm looking for a perfect example. I can already half a$$ do it haha.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 8th, 2002, 10:57 AM
#5
Hyperactive Member
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.
-
Aug 8th, 2002, 08:11 PM
#6
Thread Starter
PowerPoster
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.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 8th, 2002, 08:17 PM
#7
PowerPoster
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?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Aug 9th, 2002, 06:15 AM
#8
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
-
Aug 9th, 2002, 06:35 AM
#9
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|