Skip to content

Textbox enter

rathi rathi

Asked Jun 1, 2006, 4:34 AM EDT3 answers
Share
LinkedInX
I have a requirement give me a idea to do that. When I enter a value in the text box and press enter I have to display some values in the other text . Tell me how I have to do this. Give a idea

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Go to your form.designer.cs
    Find where it says
    //
    // textBox1
    //

    Assuming this is the textbox you want to respond when the user presses 'enter'... now add this line of code with the other textBox1 handlers...

    C#
    this.textBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(textBox1_KeyUp);
    
    
    Go to your Form1.cs and add the textBox1_KeyUp method:
    
    
    private void textBox1_KeyUp(object sender, KeyEventArgs e)
       {
       if (e.KeyCode.ToString().Equals("Return"))
          {
             // do stuff here, ie:
             textBox2.Text = "I changed to this when textBox1 received 'enter'";
          }
       }
    0
  • 0
    ...or... you can use other condition if (e.KeyValue == 13) 13 is ASCII for Enter
    0
  • 0

    good point, and using the ascii is better

    0