Imports System.Windows.Forms Imports System.ComponentModel Public NotInheritable Class MarqueeLable Inherits System.Windows.Forms.Label Private components As System.ComponentModel.IContainer Private internalTimer As System.Windows.Forms.Timer Private internalLocation As Single = 0.0F Public Sub New() MyBase.UseCompatibleTextRendering = True Me.components = New System.ComponentModel.Container() Me.internalTimer = New System.Windows.Forms.Timer(components) Me.internalTimer.Interval = 50 AddHandler internalTimer.Tick, AddressOf internalTimer_Tick MyBase.SetStyle(ControlStyles.UserPaint, True) MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True) MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True) Me.internalTimer.Start() End Sub ''' <summary> ''' テキストの位置を初期値に戻します。 ''' </summary> Public Sub ResetPosition() Me.internalLocation = 0.0F Me.Invalidate() End Sub ''' <summary> ''' 流れるスピードを指定します。 ''' </summary> <System.ComponentModel.Description("流れるスピードを指定します。")> _ <System.ComponentModel.Category("Action")> _ <System.ComponentModel.DefaultValue(20.0F)> _ Public Property Speed() As Single Get Return Math.Max(0.0F, Math.Min(CSng(Me.Width), speedValue)) End Get Set(ByVal value As Single) If value < 0.0F Then Throw New ArgumentOutOfRangeException("Speed", value, "0以上の値を指定してください。") End If speedValue = Math.Min(Me.Width, value) internalTimer.Enabled = (value <> 0) If value = 0.0F Then internalTimer.Enabled = False If Me.DesignMode Then ResetPosition() End If Else internalTimer.Enabled = True End If End Set End Property Private speedValue As Single = 20.0F Protected Overrides Sub OnPaint(e As PaintEventArgs) e.Graphics.TranslateTransform(-internalLocation, 0.0F) MyBase.OnPaint(e) End Sub Private Sub internalTimer_Tick(sender As Object, e As EventArgs) If Me.internalLocation > Me.Width Then internalLocation = -Me.Width Else internalLocation += speedValue / 10 End If Me.Invalidate() End Sub <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then Me.components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub End Class