T
trondhuso
Hi Group,
I'm to write a Ticker application that will get it's content from RSS-
feed(s), the RSS-part is not part of the problem though.
I've searched the web and found a few solutions here and there that
creates the scrolling text, but not without flickering. I then tried
to move the text into the paint sub in the form which results in
neither a scrolling text or flickering (last thing is good, but I
guess that is because there isn't anything to flicker)...
To generate this project you start up a new project and add a timer1-
control.
Project is coded in Visual Studio / Visual Basic 2005
Code attached is from devcenter which is the one I've started to use
as a base for this code:
Imports System.Xml
Imports System.Text
Public Class Form1
Dim widthX As Single
Dim heightY As Single = 0
Dim g As Graphics
Dim xmlst As String
Dim fo As Font
Dim str As String
Dim strWidth As SizeF
Dim douX As Double
Dim lblTicker As Label
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' valWidth = Me.Width
g = Me.CreateGraphics()
widthX = Me.Width
Me.loadthenews()
Timer1.Interval = 30
Timer1.Start()
fo = New Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Point)
strWidth = g.MeasureString(str, fo)
douX = strWidth.Width
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.OptimizedDoubleBuffer Or _
ControlStyles.UserPaint, True)
End Sub
Private Sub loadthenews()
Dim readXML As New XmlTextReader("C:\utvikling\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)
' g.Clear(Me.BackColor)
' Me.Update()
End Sub
Private Sub form1_hover(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseHover
Timer1.Stop()
End Sub
Private Sub form1_leave(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseLeave
Timer1.Start()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g.DrawString(str, fo, Brushes.Black, widthX, heightY)
If widthX <= (0 - douX) Then
widthX = Me.Width
Else
widthX -= 0.5
End If
End Sub
End Class
content of news.xml
<?xml version="1.0" encoding="utf-8"?>
<ticker>
<news>This article might appear on w.devarticles.com</news>
<news>This article was authored by Vikrant</news>
<news>Hover the mouse over this app</news>
<news>The timer just stopped</news>
<news>Thanx to devarticle fans</news>
<news>this ticker app is meant only for educational purpose</news>
</ticker>
I'm to write a Ticker application that will get it's content from RSS-
feed(s), the RSS-part is not part of the problem though.
I've searched the web and found a few solutions here and there that
creates the scrolling text, but not without flickering. I then tried
to move the text into the paint sub in the form which results in
neither a scrolling text or flickering (last thing is good, but I
guess that is because there isn't anything to flicker)...
To generate this project you start up a new project and add a timer1-
control.
Project is coded in Visual Studio / Visual Basic 2005
Code attached is from devcenter which is the one I've started to use
as a base for this code:
Imports System.Xml
Imports System.Text
Public Class Form1
Dim widthX As Single
Dim heightY As Single = 0
Dim g As Graphics
Dim xmlst As String
Dim fo As Font
Dim str As String
Dim strWidth As SizeF
Dim douX As Double
Dim lblTicker As Label
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' valWidth = Me.Width
g = Me.CreateGraphics()
widthX = Me.Width
Me.loadthenews()
Timer1.Interval = 30
Timer1.Start()
fo = New Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Point)
strWidth = g.MeasureString(str, fo)
douX = strWidth.Width
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.OptimizedDoubleBuffer Or _
ControlStyles.UserPaint, True)
End Sub
Private Sub loadthenews()
Dim readXML As New XmlTextReader("C:\utvikling\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)
' g.Clear(Me.BackColor)
' Me.Update()
End Sub
Private Sub form1_hover(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseHover
Timer1.Stop()
End Sub
Private Sub form1_leave(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.MouseLeave
Timer1.Start()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g.DrawString(str, fo, Brushes.Black, widthX, heightY)
If widthX <= (0 - douX) Then
widthX = Me.Width
Else
widthX -= 0.5
End If
End Sub
End Class
content of news.xml
<?xml version="1.0" encoding="utf-8"?>
<ticker>
<news>This article might appear on w.devarticles.com</news>
<news>This article was authored by Vikrant</news>
<news>Hover the mouse over this app</news>
<news>The timer just stopped</news>
<news>Thanx to devarticle fans</news>
<news>this ticker app is meant only for educational purpose</news>
</ticker>