I have a custom text field component (inherited from system.windows.forms.textbox) that I created in vb.net (2005) that handles numeric input. It works well.
I would like to suppress verified and confirmed events when firing, if the number has not changed. If the user enters a tab through the form and tabs from the text field, checked / checked events are activated.
I thought that a text field could cache a value and compare it with what is specified in the text property. If they are different from each other, I would like the validation / validation events to be executed. If they are the same, nothing starts.
I can’t figure out how to suppress the event. I tried to override the OnValidating event. This did not work.
Any ideas?
Update:
Here is a custom text field class. The idea is that I want to cache the value of a text field in a validation event. After the value is cached, the next time the user enters the checkbox, the checking event will check if _Cache is different from .Text. If so, I would like to raise the validation event to the parent form (as well as the validated event). If _cache is the same, then I do not want to raise the event on the form. In fact, the text field will work the same as in a regular text field, except that the tested and verified method only gets introduced into the form when the text changes.
Public Class CustomTextBox
Private _FirstClickCompleted As Boolean = False 'used to indicate that all of the text should be highlighted when the user box is clicked - only when the control has had focus shifted to it
Private _CachedValue As String = String.Empty
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
'check to see if the control has recently gained focus, if it has then allow the first click to highlight all of the text
If Not _FirstClickCompleted Then
Me.SelectAll() 'select all the text when the user clicks a mouse on it...
_FirstClickCompleted = True
End If
MyBase.OnClick(e)
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
_FirstClickCompleted = False 'reset the first click flag so that if the user clicks the control again the text will be highlighted
MyBase.OnLostFocus(e)
End Sub
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
If String.Compare(_CachedValue, Me.Text) <> 0 Then
MyBase.OnValidating(e)
End If
End Sub
Protected Overrides Sub OnValidated(ByVal e As System.EventArgs)
_CachedValue = Me.Text
MyBase.OnValidated(e)
End Sub
End Class
Update 2:
xpda ( , :)). OnValidating OnValidated ( ):
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
If String.Compare(_CachedValue, Me.Text) <> 0 Then
_ValidatingEventRaised = True
MyBase.OnValidating(e)
End If
End Sub
Protected Overrides Sub OnValidated(ByVal e As System.EventArgs)
If Not _ValidatingEventRaised Then Return
_CachedValue = Me.Text
_ValidatingEventRaised = False
MyBase.OnValidated(e)
End Sub