|
-
Sep 18th, 2002, 07:55 AM
#1
Thread Starter
New Member
How do you stop users entering a character in a textbox??
You know, the more I delve into .NET the more frustrating it gets!! on the keypress event of a textbox i want to make sure that any characters that are not numbers are ignored. I have sat for an hour looking through the help but as usual Microsoft never acatually provide real-world examples in their help! In previous versions of VB I could use sendKeys to send a single backspace character to delete that last character entered, but in VB.NET SendKeys seems to hang the application!
The code is as follows in the keypress handler for my Textbox
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsDigit(e.KeyChar) Then
'What do I put here to make sure that the character
'I just typed doesn't get displayed in my textbox
End If
End Sub
Oh, I don't want to use Validating event handlers or the like to go about this another way - just want to know is there something I can put in the if statement above to achieve what I'm looking for.
-
Sep 18th, 2002, 10:23 AM
#2
Member
e.Handled = True.
Harold Hoffman
-
Sep 18th, 2002, 11:13 AM
#3
Thread Starter
New Member
Thanks Harold,
I was setting this to False thinking that it would stop processing further.
Cheers
Mat
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|