Insert key press in text box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jimmy

    #1

    Insert key press in text box

    Hi all

    I am making a program whereby when the insert key is pressed in a text
    box it opens up another form with the search parameters they entered in
    the text box and automatically searches for the data. I have the code
    below however it does not work when i press the insert key. I have
    tried it with the enter key Ascii code 13 and all works fine! Is it
    something to do with Insert being a system/bios key? My code is below;

    Private Sub TelephoneTxt_Ke yPress(ByVal sender As Object, ByVal e
    As System.Windows. Forms.KeyPressE ventArgs) Handles
    TelephoneTxt.Ke yPress
    'handle telphone number search
    Dim key As Char = Microsoft.Visua lBasic.ChrW(45)
    If e.KeyChar = key And TelephoneTxt.Te xt = "" And
    SurnameTxt.Text = "" Then
    MsgBox("Please enter at least one of the two search
    parameters")
    ElseIf e.KeyChar = key Then
    CustomerSearch. ShowDialog()
    CustomerSearch. CustomerReserva tionSearch(Surn ameTxt.Text,
    TelephoneTxt.Te xt)
    End If
    End Sub


    Any help is much appreciated

    Thanks

    James

  • The Grim Reaper

    #2
    Re: Insert key press in text box

    "jimmy" <james.herringt on@tiscali.co.u kwrote in message
    news:1165349547 .362492.80840@1 6g2000cwy.googl egroups.com...
    Hi all
    >
    I am making a program whereby when the insert key is pressed in a text
    box it opens up another form with the search parameters they entered in
    the text box and automatically searches for the data. I have the code
    below however it does not work when i press the insert key. I have
    tried it with the enter key Ascii code 13 and all works fine! Is it
    something to do with Insert being a system/bios key? My code is below;
    >
    Private Sub TelephoneTxt_Ke yPress(ByVal sender As Object, ByVal e
    As System.Windows. Forms.KeyPressE ventArgs) Handles
    TelephoneTxt.Ke yPress
    'handle telphone number search
    Dim key As Char = Microsoft.Visua lBasic.ChrW(45)
    If e.KeyChar = key And TelephoneTxt.Te xt = "" And
    SurnameTxt.Text = "" Then
    MsgBox("Please enter at least one of the two search
    parameters")
    ElseIf e.KeyChar = key Then
    CustomerSearch. ShowDialog()
    CustomerSearch. CustomerReserva tionSearch(Surn ameTxt.Text,
    TelephoneTxt.Te xt)
    End If
    End Sub
    >
    >
    Any help is much appreciated
    >
    Thanks
    >
    James
    >
    James,

    The KeyPress event doesn't fire for the insert key, as it doesn't produce a
    character (e.KeyChar).
    You can use the KeyDown or KeyUp event to trap the Insert key;

    Private Sub TelephoneTxt_Ke yDown(ByVal sender As Object, ByVal e As System.
    _
    Windows.Forms.K eyEventArgs) Handles TelephoneTxt.Ke yDown
    ' Handle telphone number search
    If e.KeyCode = Keys.Insert And TelephoneTxt.Te xt = "" And
    SurnameTxt.Text = "" Then
    MsgBox("Please enter at least one of the two search parameters")
    ElseIf e.KeyCode = Keys.Insert Then
    CustomerSearch. ShowDialog()
    CustomerSearch. CustomerReserva tionSearch(Surn ameTxt.Text,
    TelephoneTxt.Te xt)
    End If
    End Sub

    Hope that helps.
    _______________ ______________
    The Grim Reaper


    Comment

    • Rad [Visual C# MVP]

      #3
      Re: Insert key press in text box

      On 5 Dec 2006 12:12:27 -0800, jimmy wrote:
      Private Sub TelephoneTxt_Ke yPress(ByVal sender As Object, ByVal e
      As System.Windows. Forms.KeyPressE ventArgs) Handles
      TelephoneTxt.Ke yPress
      'handle telphone number search
      Dim key As Char = Microsoft.Visua lBasic.ChrW(45)
      If e.KeyChar = key And TelephoneTxt.Te xt = "" And
      SurnameTxt.Text = "" Then
      MsgBox("Please enter at least one of the two search
      parameters")
      ElseIf e.KeyChar = key Then
      CustomerSearch. ShowDialog()
      CustomerSearch. CustomerReserva tionSearch(Surn ameTxt.Text,
      TelephoneTxt.Te xt)
      End If
      End Sub
      >
      Any help is much appreciated
      >
      Thanks
      >
      James
      Hey james,

      Try the KeyDown event instead

      --
      Bits.Bytes

      Comment

      • jimmy

        #4
        Re: Insert key press in text box

        Thanks to both you guys!

        Comment

        Working...