C# Crew: how do I have a textbox respond to Enter?

Discussion in 'OT Technology' started by Jumpem, Sep 30, 2004.

  1. Jumpem

    Jumpem OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    32,377
    Likes Received:
    165
    I want it to throw an event only when Enter is pressed. Not whenever any of the text changes. Any ideas? Thanks! :wavey:
     
  2. Jumpem

    Jumpem OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    32,377
    Likes Received:
    165
    It's a windows form. How do I set up the key listener event? I tried using "KeyPress" but can't figure out how to only listen for Enter.
     
  3. velkropie

    velkropie Guest

    you would have to do and on key press event, and enter the name or code(ASCII) of the "enter" key. you can also set up the on text change event of the textbox...
    i've never hear of a key listening event?
    if this doesn't help maybe you should elaborate on it..i don't think you are suing the right lingo....
     
  4. Jumpem

    Jumpem OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    32,377
    Likes Received:
    165
    Here is what I was trying to use:
    this.displayTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(displayTextBox_KeyPress);

    I tried to use the text change event, but it gets triggered as soon as they enter one digit, say "4". But we don't want it to trigger until an entire number is entered, such as "435".
     
  5. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Code:
                    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    		{
    			if(e.KeyChar == (char)13)
    				MessageBox.Show("return was pressed");
    		}
    
     

Share This Page