I'm new to the ticker stuff and specifically to the xml reader functions of .NET, I've got a flicker-free news ticker from this website, and it is working fine.
Now, I want to convert the XmlTextReader to a plain text reader so I can this news ticker to my project. Eventually I will store the news ticker text to database so I guess the first that I need to work out is how to convert that code.
Here's the XmlTextReader function
I want to convert it to something simple like thisCode:Private Sub loadthenews() Dim readXML As New XmlTextReader(Directory.GetCurrentDirectory & "\news.xml") While readXML.Read() If readXML.NodeType = XmlNodeType.Text Then str += " " & readXML.Value End If End While End Sub
and heres the complete code for the flicker-free news ticker if that mattersCode:Private Sub loadthenews() Dim news As String = "The quick brown fox jumps over the lazy dog" 'Read the news variable letter by letter so I can ticker it. End Sub
Code:Imports System.Xml Imports System.Text Imports System.IO Public Class Form1 Dim txtTicker As String = "NTB er verdens beste sted å jobbe!" 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 Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 'Debug.Write(vbCr & strwidth.Width & vbCr) 'Debug.Write(String.Format("widthX = {0}", CStr(widthX) & vbCr)) ' Debug.Write("Dette er str: " & str) SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True) e.Graphics.Clear(Me.BackColor) e.Graphics.DrawString(str, fo, Brushes.Black, widthX, heightY) e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias ' e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed ' Debug.Write(String.Format("the string width is {0}", CStr(strwidth.Width))) If widthX <= (0 - douX) Then widthX = Me.Width Else widthX -= 1 End If e.Dispose() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Width = Screen.PrimaryScreen.WorkingArea.Width Me.Location = New Point(0, 20) Me.MaximumSize = New Point(Screen.PrimaryScreen.WorkingArea.Width, 150) Me.Height = 150 Me.MaximizeBox = False Me.MinimizeBox = False Me.Text = "" Me.Icon = Nothing 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 = 1 Timer1.Start() fo = New Font("SEGOE UI", 16, FontStyle.Regular, GraphicsUnit.Point) strwidth = g.MeasureString(str, fo) douX = strwidth.Width End Sub Private Sub loadthenews() Dim readXML As New XmlTextReader(Directory.GetCurrentDirectory & "\news.xml") While readXML.Read() If readXML.NodeType = XmlNodeType.Text Then str += " " & readXML.Value End If End While End Sub Private Sub tickerTypeWriter() Dim a Dim lblTicker As New Label Me.Controls.Add(lblTicker) For a = 1 To txtTicker.Length lblTicker.Text = txtTicker.Substring(0, a) & "_" System.Threading.Thread.Sleep(100) lblTicker.Update() Next End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.Refresh() End Sub End Class




Reply With Quote
