I have been searching the form for a way to scroll text in a label control kinda like a marquee. I found the following code:
Code:
Static counter As Integer = 0
Dim scrollingText As String = "This is some scrolling text that I want to see"
If counter = scrollingText.Length Then counter = 0
lblPlaying.Text = scrollingText.Substring(counter) & scrollingText & scrollingText & scrollingText
counter += 1
The problem I am having is this is not a clean scroll... It is scrolling character for character on the left side of the label but the right side of label is displaying word by word.
No that is physically moving the control on the form. I just need to move the text. Reason being is if the text is to long for the label control, I just want to scroll it.
Well, that would take a major add-in for the control to cycle through an array or list of text you want to display. I will look into it though. Might not be to bad to manage.
It will take me a little time also, this control was mainly written for another application I am working on, just give me a little time. Hopefully by tomorrow I will have something put together.
"Don't try to be a great man. Just be a man and let history make its own judgement."
Private Sub loadthenews()
Dim readXML As New XmlTextReader("e:\news.xml")
While readXML.Read()
If readXML.NodeType = XmlNodeType.Text Then
ScrollingMarquee1.MarqueeText += " " & readXML.Value
End If
End While
End Sub
I have this in my app to load the xml text. this loads the text on form_load..
i need to reload the news on the moment that the text cycles .. i could build a timer to reload the text every 10 min ..
is it also possible that, if the text is gone on the right .. that the text appears letter for letter again on the left .. at this moment when the text is gone of the left .. the full text appears again in the scrollbar and then starts scrolling ..
btw .. was this changed in the new version .. cause i thought on the old version the text appeared letter for letter of the left.
Above the marquee i have a picturebox. that picturebox has a random picture from a certain directory. i want to refresh that picturebox after a few seconds with a new random picture. this while the marquee keeps on running without delay.
Attached is the new source code for the Marquee control. It allows you to set which direction you want the text to scroll by setting ScrollLeftToRight to True or False.
EDIT: UPDATED CONTROL BELOW
Last edited by .NetNinja; Nov 6th, 2008 at 01:21 PM.
"Don't try to be a great man. Just be a man and let history make its own judgement."
when the text is at the end .. the control is cleared completely .. i want to text to scroll completely of the screen .. and then the last letter of the text is of the screen .. then the text should start again on the right side...
What size is the control on your form?
What font are you using?
EDIT:
I have noticed an issue when the font size and/or name is changed. To account for this you might want to modify the calculation (y = -5 * -x) in the tmrMain_Tick subroutine. This will vary on a case by case basis. That is one of the reason I provided this in full source. If a universal solution is found I will post an update to the source.
Note on a variations on the calculation, only the static value (-5) needs to be modified, the variables should remained untouched.
Last edited by .NetNinja; Nov 6th, 2008 at 10:41 AM.
"Don't try to be a great man. Just be a man and let history make its own judgement."
What size is the control on your form?
What font are you using?
EDIT:
I have noticed an issue when the font size and/or name is changed. To account for this you might want to modify the calculation (y = -5 * -x) in the tmrMain_Tick subroutine. This will vary on a case by case basis. That is one of the reason I provided this in full source. If a universal solution is found I will post an update to the source.
Note on a variations on the calculation, only the static value (-5) needs to be modified, the variables should remained untouched.
Thanks .. i'v solved it also by adding a few spaces to the end of ScrollingMarquee1.MarqueeText
Okay the new version has a property for text direction. Also now all fonts and font sizes work. Also it will scroll like a "true" marquee, and will NOT start at the first few characters of the text.
Last edited by .NetNinja; Nov 10th, 2008 at 11:15 AM.
"Don't try to be a great man. Just be a man and let history make its own judgement."
"Well, that would take a major add-in for the control to cycle through an array or list of text you want to display. I will look into it though. Might not be to bad to manage."
I'v add a timer .. that reads a xml file every x-seconds .. and then updates ScrollingMarquee1.MarqueeText. but the text is not updated and the marquee is getting really slow ..
Private Sub LoadTheNews()
Dim readXML As New XmlTextReader("c:/tmp/news.xml")
While readXML.Read()
If readXML.NodeType = XmlNodeType.Text Then
ScrollingMarquee1.MarqueeText += " " & readXML.Value
End If
End While
End Sub
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
LoadTheNews()
End Sub
You are never clearing the text, so every 5 seconds the Text gets longer and longer.
Try:
Code:
Private Sub LoadTheNews()
Dim readXML As New XmlTextReader("c:/tmp/news.xml")
ScrollingMarquee1.MarqueeText = ""
While readXML.Read()
If readXML.NodeType = XmlNodeType.Text Then
ScrollingMarquee1.MarqueeText += " " & readXML.Value
End If
End While
End Sub