Results 1 to 3 of 3

Thread: How do you stop users entering a character in a textbox??

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    6

    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.

  2. #2
    Member
    Join Date
    Sep 2002
    Posts
    37
    e.Handled = True.

    Harold Hoffman

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    6

    Thumbs up

    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
  •  



Click Here to Expand Forum to Full Width