Determine If Changed Event Occurred from User Input Or Not

后端 未结 6 817
借酒劲吻你
借酒劲吻你 2021-01-18 00:38

In C#, the Changed event for a control (say, a numericupdown) gets fired whether the value was change directly by the user or if it was changed programatically as the result

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 01:01

    1. Inherit NumericUpDown Class
    2. Create a flag for determine value changed programmatically, or changed by GUI
    3. Overload Value Property to set above flag

    Here is my solution in VB .NET

        Private m_blnIsValueChangedByGui As Boolean = True
    
        Public Property IsValueChangedByGui() As Boolean
            Get
                Return m_blnIsValueChangedByGui
            End Get
            Set(ByVal value As Boolean)
                m_blnIsValueChangedByGui = value
            End Set
        End Property
    
        Public Shadows Property Value() As Decimal
            Get
                Return MyBase.Value
            End Get
            Set(ByVal value As Decimal)
                IsValueChangedByGui = False
    
                If (value > Me.Maximum) Then
                    MyBase.Value = Me.Maximum
                ElseIf (value < Me.Minimum) Then
                    MyBase.Value = Me.Minimum
                Else
                    MyBase.Value = value
                End If
    
                IsValueChangedByGui = True
            End Set
        End Property
    

提交回复
热议问题