VB.Net
  Home arrow VB.Net arrow Page 4 - 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 
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 / 126
    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 - Code


    (Page 4 of 5 )

    • Open Visual Studio.Net
    • Select the windows application template and enter NewsTicker as its name
    • Change the name of  form1.vb to NewsTicker.vb
    • In the design view, drag the timer control and drop it on the form
    • Decrease the height of the form such that it accommodates only the news string.  In my app width = 710 and height = 70
    • Drag the context menu control and drop it on the component tray.  I use it to code an alternate method to dismiss the form when the user right clicks on the form
    • Type &Exit in the context menu item, so that it might display Exit when the user right clicks it
    • Associate the context menu by using the form’s property page
    • Switch to code view and code it as given below:


    I’ve omitted form designer generated code

    Imports System.Text    'used for string manipulations
    Imports System.Xml     ' used for XML reading
    Public Class NewsTicker
        Inherits System.Windows.Forms.Form

    Dim widthX As Single
        Dim heightY As Single = 0
        Dim g As Graphics
        Dim xmlst As String      'string from the xml file
        Dim fo As Font
        Dim str As String
        Dim strwidth As SizeF    'gets the xml string's width and height
        Dim douX As Double       'stores the xmlstring's width     

        Private Sub NewsTicker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            g = Me.CreateGraphics()  ‘get the graphics object of the form
            widthX = Me.Width        ' x co- ordinate or width
            ' Debug.Write(String.Format("The width is {0}", ‘CStr(Me.Width)))
            Me.loadthenews()        
            Dim gr As Graphics
            Timer1.Interval = 100
            Timer1.Start()
            fo = New Font("Times New Roman", 14, FontStyle.Bold, GraphicsUnit.Point)
            strwidth = g.MeasureString(str, fo)
            douX = strwidth.Width
        End Sub

        Private Sub loadthenews()
            Dim readXML As New XmlTextReader("G:\vbapps\dr\news.xml")
            While readXML.Read()
                If readXML.NodeType = XmlNodeType.Text Then
                    str += "   " & readXML.Value
                End If
            End While
        End Sub
        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
                widthX = Me.Width
            Else
                widthX -= 5
            End If
        End Sub
        Private Sub NewsTicker_hover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseHover
            Timer1.Stop()
            Debug.Write(String.Format("The string width is {0}", CStr(douX)))
        End Sub
        Private Sub NewsTicker_leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
            Timer1.Start()
        End Sub

        Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
            Application.Exit()
        End Sub
    End Class

    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...
       · Vikrant,I added couple of lines code. This stopped the flicker. May be there is a...
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek