We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Why override the onkeypress method when I inherit from the textbox class??

Thread ID:

Created:

Platform:

Replies:

28678 May 6,2005 03:44 PM UTC WinForms 0
loading
Tags: FAQ
fia
Asked On May 6, 2005 03:44 PM UTC

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 metod Onkeypress. To make the NumericTextbox I inherit from System.Windows.Forms.TextBox. Can anyone help me with these questions. Thanks for your answers Fia

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;