Home arrow VB.Net arrow Page 3 - Building a News Ticker Using VB.Net
VB.NET

Building a News Ticker Using VB.Net


In this latest article, Vikrant shows us how to create a news ticker using VB.Net and XML technologies.

Author Info:
By: R. Abhiram Vikrant
Rating: 4 stars4 stars4 stars4 stars4 stars / 160
October 31, 2003
TABLE OF CONTENTS:
  1. · Building a News Ticker Using VB.Net
  2. · Why XML?
  3. · Application Basics
  4. · Code
  5. · Conclusion

print this article
SEARCH DEVARTICLES

Building a News Ticker Using VB.Net - Application Basics
(Page 3 of 5 )

Scrolling

There are two vital parameters necessary to be calculated for scrolling:

  1. The String width
  2. The Form Width

Calculating Width

Width plays an important role in our application. We calculate the width of the form by simply putting:

ME.WIDTH

The above statement retrieves the width of the application for you. This width determines the starting point and ending point of the scrollable layout. To measure the string width we have to use:

System.Drawing.Graphics.MeasureString(String,System.Drawing.font)

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 Control

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

   'Debug.Write(vbCr & strwidth.Width & vbCr)
   'Debug.Write(String.Format("widthX = {0}", CStr(widthX) & vbCr))

   g.Clear(Me.BackColor)       
   g.DrawString(str, fo, Brushes.Black, widthX, heightY)
   ' Debug.Write(String.Format("the string width is {0}", ‘             
   ‘   CStr(strwidth.Width)))
 
   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!

Next: Code >>

blog comments powered by Disqus
VB.NET ARTICLES

- MyClass - Implementing Polymorphism in VB.Net
- Building a News Ticker Using VB.Net
- Everything You Wanted to Know About Forms In...
- Building Assemblies with VB.Net
- Simple VB.NET Notify Icon with Panel Applica...
- Regular Expressions in .NET
- String Encryption With Visual Basic .NET
- Deploying Applications in VB.NET: Part 1/2
- Watching Folder Activity in VB.NET
- Creating A Windows Service in VB.NET
- Implementing The Google Web Service In VB.NET
- Migrating to Visual Basic.NET from Visual Ba...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials