Building a News Ticker Using VB.Net


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

2 responses to “Building a News Ticker Using VB.Net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s