Results 1 to 7 of 7

Thread: key down, suppress key problem

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    38

    key down, suppress key problem

    i have a telephone number textbox that i have used the key down event to suppress any other keys besides 0-9 and the backspace key. i have a label beside it.
    i want to display a message on lbltelephone when the user presses an alphabetic key that the textbox is for numbers only,and the message should disapper when the user inputs correct values...
    currently i have

    e.suppresskeypress=true
    lbltelephone.text="no"

  2. #2
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: key down, suppress key problem

    If keypress is invalid
    do what you have done
    Else
    lbltelephone.text=""

    end if

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    38

    Re: key down, suppress key problem

    this is the code i have, how do i incooperate your suggestion here?

    Private Sub txtTel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTel.KeyDown
    If e.KeyCode = Keys.D0 Or e.KeyCode = Keys.D1 Or e.KeyCode = Keys.D2 Or e.KeyCode = Keys.D3 Or _
    e.KeyCode = Keys.D4 Or e.KeyCode = Keys.D5 Or e.KeyCode = Keys.D6 Or e.KeyCode = Keys.D7 Or _
    e.KeyCode = Keys.D8 Or e.KeyCode = Keys.D9 Or e.KeyCode = Keys.Back Then
    Else
    e.SuppressKeyPress = True
    End If
    If e.KeyCode = Keys.Escape Then
    txtTel.Text = ""
    End If
    If e.KeyData = Keys.Return Then
    txtPerson.Focus()
    End If
    End Sub

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: key down, suppress key problem

    @ Chris,

    There was no need to start a new thread! I ask a mod to move the old one and have posted a vb.net solution in the thread here.

    Edit:

    See post #10.
    Last edited by Nightwalker83; Nov 21st, 2012 at 05:24 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2012
    Posts
    38

    Re: key down, suppress key problem

    oh i didnt know, thanks, still xperiencing the same problem tho

  6. #6
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: key down, suppress key problem

    Code:
    Private Sub txtTel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTel.KeyDown
    If e.KeyCode = Keys.D0 Or e.KeyCode = Keys.D1 Or e.KeyCode = Keys.D2 Or e.KeyCode = Keys.D3 Or _
              e.KeyCode = Keys.D4 Or e.KeyCode = Keys.D5 Or e.KeyCode = Keys.D6 Or e.KeyCode = Keys.D7 Or _
              e.KeyCode = Keys.D8 Or e.KeyCode = Keys.D9 Or e.KeyCode = Keys.Back Then
       lbltelephone.Text = ""
    Else
       e.SuppressKeyPress = True
       lbltelephone.Text = "No"
    End If
    If e.KeyCode = Keys.Escape Then
       txtTel.Text = ""
    End If
    If e.KeyData = Keys.Return Then
       txtPerson.Focus()
    End If
    End Sub

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: key down, suppress key problem

    What are you going to do if the user pastes a value into the textbox?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

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