where string (in this app) is the text from the news tag of our XML file. Font will be described in the application.
Manipulating the XML File
We can browse through the XML tag collections easily. Further to simplify the process, we use XMLTextReader in this app. Let’s look at it in detail:
Private Sub loadthenews() Dim readXML As New XmlTextReader("G:\vbapps\dr\news.xml") ‘the file location might differ in your computer, make sure you add the correct file path
While readXML.Read() If readXML.NodeType = XmlNodeType.Text Then str += " " & readXML.Value End If End While End Sub
We are using the loadthenews() method to load the XML file and also for building the scrolling text from the news tag(s).
As you can easily understand, the first line loads the XML file from the given file URL. readXML.read() lets the application browse through the XML news tags. The following two lines makes sure that the strings are appended only if they are of node type Text (in our case it is the <news> tag). These lines of code code are used to construct the string parameter for the drawstring method.
Timer is the driver of this ticker application. The main purpose of the timer is to activate the Graphics.Drawstring method at a specified interval until the timer stops. We introduce this drawstring method in the Timer1.Tick event handler. Hence, we draw the string at a decremented location with respect to the timer interval. I’ll explain about decrementing the location later.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If widthX <= (0 - douX) Then ‘check whether all text ‘have been scrolled widthX = Me.Width Else widthX -= 5 End If END SUB
In the code above, we refresh the form with the application’s background color, draw the string at the given location (widthX and heightY). On the next line, we check whether the text has scrolled completely or not. If yes, we scroll it from the starting point (Me.Width); otherwise, decrease the widthX value by -5, so that drawstring paints in the new WidthX value to get the scrolling effect.
That’s it for the scrolling tape. Let’s see an example!