This is code from a scrolling label control I created a while ago. It may need some tweaking, and it's written in VB.NET, you will have to convert it. It scrolls smoothly for me without and flicker. You can adjust the speed by changing the number in the 2 timer calls, or chaning the .25
in the Tick
sub.
Imports System.ComponentModel
Public Class ScrollingLabel
Inherits Label
Private _buffer As Bitmap
Private _textX As Double
Private _brush As Brush
Private _timer As Threading.Timer
Private _textWidth As Integer
Public Sub New()
MyBase.New()
If Not IsDesignMode() Then
_timer = New Threading.Timer(AddressOf Tick, Nothing, 25, Threading.Timeout.Infinite)
End If
_brush = New SolidBrush(Me.ForeColor)
_textX = Me.Width
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Using g As Graphics = Graphics.FromImage(_buffer)
g.Clear(Me.BackColor)
g.DrawString(Me.Text, Me.Font, _brush, New PointF(CSng(_textX), 0))
End Using
e.Graphics.DrawImage(_buffer, 0, 0)
End Sub
Private Sub ScrollingLabel_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If _buffer IsNot Nothing Then
_buffer.Dispose()
End If
_buffer = New Bitmap(Me.Width, Me.Height, Imaging.PixelFormat.Format32bppArgb)
End Sub
Public Overrides Property ForeColor As Color
Get
Return MyBase.ForeColor
End Get
Set(value As Color)
MyBase.ForeColor = value
If _brush IsNot Nothing Then
_brush.Dispose()
End If
_brush = New SolidBrush(Me.ForeColor)
End Set
End Property
Public Overrides Property Text As String
Get
Return MyBase.Text
End Get
Set(value As String)
MyBase.Text = value
Using g As Graphics = Graphics.FromImage(_buffer)
_textWidth = CInt(g.MeasureString(Me.Text, Me.Font).Width)
End Using
End Set
End Property
Private Sub Tick(state As Object)
If Me.Parent.InvokeRequired Then
Me.BeginInvoke(New Action(Of Object)(AddressOf Tick), New Object() {state})
End If
_textX -= 0.25
If Math.Abs(_textX) > _textWidth Then
_textX = Me.Width
End If
_timer.Change(25, Threading.Timeout.Infinite)
Me.Invalidate()
End Sub
Private Function IsDesignMode() As Boolean
If DesignMode Then
Return True
End If
Return CBool(LicenseManager.UsageMode = LicenseUsageMode.Designtime)
End Function
End Class