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


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