VB.Net
  Home arrow VB.Net arrow Page 3 - Building a News Ticker Using VB.Net
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VB.NET

Building a News Ticker Using VB.Net
By: R. Abhiram Vikrant
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 112
    2003-10-31

    Table of Contents:
  • Building a News Ticker Using VB.Net
  • Why XML?
  • Application Basics
  • Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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!

    More VB.Net Articles
    More By R. Abhiram Vikrant


       · I'm trying to create the News Ticker as advised in this article but am unable to get...
     

    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...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT