Hi when I'm creating a numeric textbox I have to override the method
Onkeypress to prevent a user of the control to use the control's Keypress
event. For example the users of the control could write code like this.
Private Sub NumericTextbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles NumericTextbox1.KeyPress
Me.NumericTextbox1.Text = e.KeyChar
End Sub
And this spoils the use of the NumericTextbox
To prevent this code to happen I have to use the code below in the NumericTextbox's class. I'm not sure why I have to do it like this, so if
anyone can explain that for me I'll be greatful. What I meen is why I have to use the method Onkeypress to take control of the Keypress event.
Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
If Asc(e.KeyChar) = 8 Then
ElseIf Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
In some books they say I have to have this code also and I don't know why. I
don't notice any difference if I have this line or not.
Public Shadows Event KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)
And finally I don't understand why I have to override the method Onkeypress,
because when I'm looking at the textbox class in WinCV.exe, I can't find the
method Onkeypress.
To make the NumericTextbox I inherit from System.Windows.Forms.TextBox.
Can anyone help me with these questions.
Thanks for your answers
Fia
Onkeypress to prevent a user of the control to use the control's Keypress
event. For example the users of the control could write code like this.
Private Sub NumericTextbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles NumericTextbox1.KeyPress
Me.NumericTextbox1.Text = e.KeyChar
End Sub
And this spoils the use of the NumericTextbox
To prevent this code to happen I have to use the code below in the NumericTextbox's class. I'm not sure why I have to do it like this, so if
anyone can explain that for me I'll be greatful. What I meen is why I have to use the method Onkeypress to take control of the Keypress event.
Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
If Asc(e.KeyChar) = 8 Then
ElseIf Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
In some books they say I have to have this code also and I don't know why. I
don't notice any difference if I have this line or not.
Public Shadows Event KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs)
And finally I don't understand why I have to override the method Onkeypress,
because when I'm looking at the textbox class in WinCV.exe, I can't find the
method Onkeypress.
To make the NumericTextbox I inherit from System.Windows.Forms.TextBox.
Can anyone help me with these questions.
Thanks for your answers
Fia