[Help]How to make scrolling text?[solved]

Posts 1–15 of 19 · Page 1 of 2
[Help]How to make scrolling text?[solved]
How would i make text that scrolls across the application like, the label starts at one side of the program, slowly moves over towards the other side then once its out of sight on the other side it moves back to where it originally was and slowly moves across the application again, how would i do this
I looked all over google but i cant seem to find it
Put label on form1, put timer on form1.
timer 1 enabled, interval 100.
go into timer1 code.

put in:
Code:
Label1.Left -= 5
If Label1.Left <= -Width Then
Label1.Left = Width
End If
End Sub
End Class
Put that shit under Private Sub Timer1_Tick
Code:
Do Until Label1.location.X = 100 'or whatever
Label1.Location = New Point(Label1.Location.X - 2, Label1.location.y)
System.Threading.Thread.Sleep(100)
Loop
Quote Originally Posted by Lolland View Post
Code:
Do Until Label1.location.X = 100 'or whatever
Label1.Location = New Point(Label1.Location.X - 2, Label1.location.y)
System.Threading.Thread.Sleep(100)
Loop
Eugh, timer is a much better option unless you're running this in a different thread with proper delegates. System.Threading.Thread.Sleep sleeps the thread that the code was executed from, which in this case will be the UI thread. This means that during that sleep time, no other code on the UI thread will be executed. If you're trying to have scrolling text running asynchronously, either use a timer or another thread. The timer still runs on the UI thread, but won't lag the thread. Here's one with delegates and threading:

[php]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim scrollThread As New Threading.Thread(AddressOf Scrolling)
scrollThread.Start()
End Sub

Private Delegate Sub MoveLabelInvoker(ByVal lbl As Label)

Private Sub MoveLabel(ByVal lbl As Label)
If lbl.InvokeRequired Then
lbl.Invoke(New MoveLabelInvoker(AddressOf MoveLabel), lbl)
Else
If Not lbl.Left + lbl.Width <= 0 Then
lbl.Left -= 1
Else
lbl.Left = Me.Width
End If
End If
End Sub

Private Sub Scrolling()
Do
MoveLabel(Me.Label1)
System.Threading.Thread.Sleep(30)
Loop
End Sub
[/php]

Enjoy.
Quote Originally Posted by Jason View Post


Eugh, timer is a much better option unless you're running this in a different thread with proper delegates. System.Threading.Thread.Sleep sleeps the thread that the code was executed from, which in this case will be the UI thread. This means that during that sleep time, no other code on the UI thread will be executed. If you're trying to have scrolling text running asynchronously, either use a timer or another thread. The timer still runs on the UI thread, but won't lag the thread. Here's one with delegates and threading:

[php]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim scrollThread As New Threading.Thread(AddressOf Scrolling)
scrollThread.Start()
End Sub

Private Delegate Sub MoveLabelInvoker(ByVal lbl As Label)

Private Sub MoveLabel(ByVal lbl As Label)
If lbl.InvokeRequired Then
lbl.Invoke(New MoveLabelInvoker(AddressOf MoveLabel), lbl)
Else
If Not lbl.Left + lbl.Width <= 0 Then
lbl.Left -= 1
Else
lbl.Left = Me.Width
End If
End If
End Sub

Private Sub Scrolling()
Do
MoveLabel(Me.Label1)
System.Threading.Thread.Sleep(30)
Loop
End Sub
[/php]

Enjoy.
As i stated my way would work better... Thanks for posting your shit jason, way better than mine and lollands good work!

I also noticed no one thanked me, lolland, or jason for helping Bombs... I guess lately people have forgotten THERES A FUCKING THANKS BUTTON!!!!!!!!!
Quote Originally Posted by ken53406 View Post
As i stated my way would work better... Thanks for posting your shit jason, way better than mine and lollands good work!

I also noticed no one thanked me, lolland, or jason for helping Bombs... I guess lately people have forgotten THERES A FUCKING THANKS BUTTON!!!!!!!!!
That's common on MPGH
My way works exactly the same, its smoother and its a million times easier lol
Mine should run smoother now.
Erm mmkay idc just posting to help. Whichever he decides is best
Nice coding. Both of you
Don't fight about which code to use though D:
I assumed he would be using different threads.
Quote Originally Posted by Lolland View Post
I assumed he would be using different threads.
Well then it's going to fail regardless 'cos you're accessing the control outside the thread it was created on = dead.
you can keep the label in the same position with this:

(undah the timah)
Code:
label1.text = label1.text + label1.remove(1,label1.length) 'copies the first letter to the end
label1.remove(0,1) ' removes the first letter
so this would happen:

scrolling
crollings
rollingsc
ollingscr
llingscro
lingscrol
ingscroll
ngscrolli
gscrollin
scrolling

and so on...
i used youtube i found a tut that works but doesn't reset
Quote Originally Posted by cosconub View Post
i used youtube i found a tut that works but doesn't reset
You don't need a non-working youtube tutorial for such task
Posts 1–15 of 19 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Talk with us