Wrox Programmer Forums
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 6th, 2005, 05:19 AM
Fia Fia is offline
Registered User
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Onkeypress

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 spoil 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.

Protected Overrides Sub OnKeyPress(ByVal e As
     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


Similar Threads
Thread Thread Starter Forum Replies Last Post
onkeypress move to next control [except when the f kamii47 ASP.NET 2.0 Professional 2 September 11th, 2007 03:47 AM
Unwanted Char - OnKeypress event needelp Access VBA 3 December 19th, 2006 07:29 PM
onkeypress not supported in asp.net 2.0 ?? savan_thakkar ASP.NET 2.0 Professional 1 March 19th, 2006 04:46 PM
How to hijack backspace onkeypress (or keydown)? scubaduba Javascript How-To 1 November 8th, 2004 05:41 AM
OnKeyPress to call VBSCRIPT validation Ron Howerton HTML Code Clinic 5 September 16th, 2003 10:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.