在numericupdown上手动ValueChanged

时间:2014-05-23 14:01:21

标签: vb.net

我尝试了这三个Handler,现在我可以将错误返回到valuechange或KeyPress(例如,按Enter键)。 使用KeyPress事件,sub被调用一次用于控制;实际上,如果释放出第一个控件中的错误然后再进行其他返回就相同;第二次不打电话给子 第二个问题是当我尝试从另一个使用鼠标移动时触发此错误。

Sub () ...
AddHandler advacedNumeric.ValueChanged, AddressOf ValueChanged
    AddHandler advacedNumeric.MouseEnter, AddressOf ValueChanged
    AddHandler advacedNumeric.KeyPress, AddressOf ValueChanged
End Sub ...

Public Sub SetError(ByVal numeric As UtAdvancedNumeric, ByVal errorDescription As     String)
    mErrorProvider.Clear()
    mErrorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink
    mErrorProvider.SetIconAlignment(numeric, ErrorIconAlignment.MiddleRight)
    mErrorProvider.SetError(numeric, errorDescription)
End Sub

Public Sub ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim advancedNumeric As New UtAdvancedNumeric
    advancedNumeric = sender
    mErrorProvider.Clear()
    Dim value As Double = 0
    Try
        value = advancedNumeric.ActiveControl.Text
    Catch
        value = 0
    End Try

    Dim min As Double = advancedNumeric.MinValue
    If value < min Then
        SetError(advancedNumeric, "Valore inferiore al minimo consentito di : " & min & "")
        advancedNumeric.Value = min
    End If
    Dim max As Double = advancedNumeric.MaxValue
    If value > max Then
        SetError(advancedNumeric, "Valore superiore al minimo consentito di : " & max & "")
        advancedNumeric.Value = max
    End If
   End Sub

UtAdvancedNumeric是一个基于numericUpDown的自定义控件。 谢谢你的帮助

0 个答案:

没有答案