Imports System.ComponentModel
''' <summary>
''' Scolls text across the screen.
''' </summary>
Public Class MarqueeLabel
#Region " Types "
''' <summary>
''' Defines constants that indicate the direction the text scolls across the screen.
''' </summary>
Public Enum MarqueeDirection
''' <summary>
''' Text scrolls to the left, reappearing at the right edge of the control.
''' </summary>
Left
''' <summary>
''' Text scrolls to the right, reappearing at the left edge of the control.
''' </summary>
Right
End Enum
#End Region 'Types
#Region " Variables "
''' <summary>
''' The direction the text scrolls across the screen.
''' </summary>
Private _direction As MarqueeDirection
''' <summary>
''' The distance the text moves at each time interval.
''' </summary>
Private _distanceInterval As Integer = 5
#End Region 'Variables
#Region " Properties "
''' <summary>
''' The direction the text scrolls across the screen.
''' </summary>
''' <value>
''' <see cref="MarqueeDirection">Left</see> if the text scrolls to the left; <see cref="MarqueeDirection">Right</see> if the text scrolls to the right.
''' </value>
<Category("Marquee")> _
<Description("The direction the text moves.")> _
Public Property Direction() As MarqueeDirection
Get
Return Me._direction
End Get
Set(ByVal value As MarqueeDirection)
Me._direction = value
End Set
End Property
''' <summary>
''' The distance the text moves each time interval.
''' </summary>
''' <value>
''' An <b>Int32</b> containing the number pixels the text will move.
''' </value>
''' <remarks>
''' The smaller the value the smoother the effect but the slower the text will move across the screen.
''' </remarks>
<Category("Marquee")> _
<DefaultValue(5)> _
<Description("The number of pixels the text moves each time.")> _
Public Property DistanceInterval() As Integer
Get
Return Me._distanceInterval
End Get
Set(ByVal value As Integer)
Me._distanceInterval = value
End Set
End Property
''' <summary>
''' Indicates whether the text will scroll or not.
''' </summary>
''' <value>
''' <b>True</b> if the text will scroll; otherwise, <b>False</b>.
''' </value>
<Category("Marquee")> _
<DefaultValue(False)> _
<Description("Whether or not the text moves.")> _
Public Property MarqueeEnabled() As Boolean
Get
Return Me.marqueeTimer.Enabled
End Get
Set(ByVal value As Boolean)
Me.marqueeTimer.Enabled = value
If Not value Then
Me.textLabel.Left = 0
End If
End Set
End Property
''' <summary>
''' The text displayed on the label.
''' </summary>
''' <value>
''' A <b>String</b> containing the text to display.
''' </value>
<Category("Marquee")> _
<Description("The text displayed on the control.")> _
Public Property MarqueeText() As String
Get
Return Me.textLabel.Text
End Get
Set(ByVal value As String)
Me.textLabel.Text = value
End Set
End Property
''' <summary>
''' The time interval between movements of the text.
''' </summary>
''' <value>
''' An <b>Int32</b> containing a number of milliseconds.
''' </value>
''' <remarks>
''' The smaller the value the faster the text will move.
''' </remarks>
<Category("Marquee")> _
<DefaultValue(100)> _
<Description("The number of milliseconds between text movements.")> _
Public Property TimeInterval() As Integer
Get
Return Me.marqueeTimer.Interval
End Get
Set(ByVal value As Integer)
Me.marqueeTimer.Interval = value
End Set
End Property
#End Region 'Properties
#Region " Event Handlers "
Private Sub marqueeTimer_Tick(ByVal sender As Object, _
ByVal e As EventArgs) Handles marqueeTimer.Tick
Select Case Me._direction
Case MarqueeDirection.Left
Me.MoveLabelLeft()
Case MarqueeDirection.Right
Me.MoveLabelRight()
End Select
End Sub
#End Region 'Event Handlers
#Region " Methods "
''' <summary>
''' Moves the text to the left by the current distance interval.
''' </summary>
''' <remarks>
''' If the text moves beyond the visible area of the control it wraps back to the right edge.
''' </remarks>
Private Sub MoveLabelLeft()
Me.textLabel.Left -= Me._distanceInterval
If Me.textLabel.Right <= 0 Then
'Wrap the text back to the right edge of the control.
Me.textLabel.Left = Me.Width
End If
End Sub
''' <summary>
''' Moves the text to the right by the current distance interval.
''' </summary>
''' <remarks>
''' If the text moves beyond the visible area of the control it wraps back to the left edge.
''' </remarks>
Private Sub MoveLabelRight()
Me.textLabel.Left += Me._distanceInterval
If Me.textLabel.Left >= Me.Width Then
'Wrap the text back to the left edge of the control.
Me.textLabel.Left = -Me.textLabel.Width
End If
End Sub
#End Region 'Methods
End Class