VB6のUpDownコントロールのように、Valueプロパティの値がMinimumプロパティの値より小さい値になったらMaximumプロパティの値に、Valueプロパティの値がMaximumプロパティの値より大きい値になったらMinimumプロパティの値に折り返すNumericUpDownコントロールです。
UpDownコントロールのWarpプロパティをONにした際の挙動のみを拡張しているので、それ以外の部分は必要に応じて実装してください。
' This software is distributed under the license of NYSL. ' ( http://www.kmonos.net/nysl/ ) ''' <summary> ''' VB6のUpDownのように値の折り返しに対応したNumericUpDown ''' </summary> Public Class WrapNumericUpDown Inherits NumericUpDown Private _wrap As Boolean = False Private _minimum As Decimal Private _maximum As Decimal ''' <summary> ''' 最小値 ''' </summary> ''' <returns></returns> Public Shadows Property Minimum As Decimal Get Return _minimum End Get Set(value As Decimal) _minimum = value MyBase.Minimum = value - 1 End Set End Property ''' <summary> ''' 最大値 ''' </summary> ''' <returns></returns> Public Shadows Property Maximum As Decimal Get Return _maximum End Get Set(value As Decimal) _maximum = value MyBase.Maximum = value + 1 End Set End Property ''' <summary> ''' 折り返しフラグ ''' Trueの場合、Valueプロパティの値がMinimumプロパティの値より小さい値になったらMaximumプロパティの値に、Valueプロパティの値がMaximumプロパティの値より大きい値になったらMinimumプロパティの値に調整 ''' </summary> ''' <returns></returns> Public Property Wrap As Boolean Get Return _wrap End Get Set(value As Boolean) _wrap = value End Set End Property ''' <summary> ''' ''' </summary> ''' <param name="e"></param> Protected Overrides Sub OnValueChanged(e As EventArgs) If _wrap Then If Me.Value <= MyBase.Minimum Then Me.Value = Me.Maximum ElseIf Me.Value >= MyBase.Maximum Then Me.Value = Me.Minimum End If Else If Me.Value < Me.Minimum Then Me.Value = Me.Minimum ElseIf Me.Value > Me.Maximum Then Me.Value = Me.Maximum End If End If MyBase.OnValueChanged(e) End Sub End Class
Please give us your valuable comment