How to get a srolling text?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
12 posts Page 1 of 2
Contributors
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

How to get a srolling text?
geenID
Hello, sorry my english isn't very good.

How to get a scrolling text (in a textbox or label), from down to high?


I have this code, it's scrolling from right to left, and "timscroll" = timer1
Code: Select all
Private Sub timscroll_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timscroll.Tick
        If Label1.Left = 0 - Label1.Width Then
            Label1.Left = Me.Width
            Label1.Left = Label1.Left - 1
        Else
            Label1.Left = Label1.Left - 1
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Left = Me.Width

    End Sub
btw; I use ms vb 2010
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: How to get a srolling text?
mandai
Scrolling text from bottom to top?
Try this:
Code: Select all
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim starting As String = "starting value "

        Dim out As String = ""
        For i As Integer = 0 To starting.Length - 1
            out += starting(i) & vbLf
        Next

        Label1.Text = out
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Stop()
        Label1.Text = Label1.Text.Insert(Label1.Text.Length, Label1.Text.Substring(0, 2))

        Label1.Text = Label1.Text.Remove(0, 2)
        Timer1.Start()
    End Sub
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: How to get a srolling text?
geenID
it works, but that is not exactly what I mean:

Now it scrolls char for char to down, lile this:

t
e
x
t

h
e
r
e


But I would like this:

text here


The scroll-position must be scrolling over the whole form
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: How to get a srolling text?
mandai
Scroll position? For right to left scrolling you don't need to use the Form1_Load part, just change the count parameter in substring/remove to 1 and start the timer.
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: How to get a srolling text?
geenID
I think it's better to show you an example, so download this little example program, and push the about button, to see what I mean :)

http://www.mediafire.com/?e19v9g32axmmi10
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: How to get a srolling text?
Lewis
i think he wants a marquee
Image
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: How to get a srolling text?
geenID
I have no idea how it's called, but I would it exactly as the example :)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: How to get a srolling text?
mandai
Oh if the label itself has to scroll instead of the text try:
Code: Select all
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        
        Label1.Top -= 1
        If Label1.Top < 0 Then ' label won't go above the top of the form
            Label1.Top = 10 'this is the original height
        End If
    End Sub
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: How to get a srolling text?
geenID
Yes, It works!

But if the text is for the first time at the top, it will stay there.
Now I want, if the text for the first time at top, the text disappears and show again from bottom (like in the example) and repeat that for x times
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: How to get a srolling text?
mandai
This should work:
Code: Select all
    Dim times As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Stop()
        For i As Integer = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(i) Is Label Then
                Me.Controls(i).Top -= 1
                If Me.Controls(i).Top < 0 Then
                    Me.Controls(i).Top = 40
                End If
            End If

        Next

        times += 1

        If times < x Then
            Timer1.Start()
        End If

    End Sub
If you want a fade effect you will have to change the label's Paint event or use a graphics object on an image to draw strings.
12 posts Page 1 of 2
Return to “Coding Help & Support”