locked
triggering button click event on pressing enter key RRS feed

  • Question

  • hi all, i have next button in one panel .when user enters his details in text boxes of that panel and press the enter key i need next_click event to trigger ..which will redirect to the next panel in same form ..can any one help me for doin this...... thanks in advance
    Tuesday, July 26, 2011 5:12 AM

Answers

  • Hi Anup_89,

    Use KeyDown to navigate enter event so that next_click event will be trigger.

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
          if (textBox1.Text != "")
          {
            if (e.KeyCode == Keys.Enter)
            {
              btnNext.Focus();
              btnNext.PerformClick();
            }
          }
        }
    
        private void btnNext_Click(object sender, EventArgs e)
        {
          panel1.Visible = false;
          panel2.Visible = true;
          MessageBox.Show("...");
        }
    


    Hope it helps.

    Thank you.

    Hardz

    • Proposed as answer by RohitArora Tuesday, July 26, 2011 10:30 AM
    • Marked as answer by Helen Zhou Friday, July 29, 2011 7:33 AM
    Tuesday, July 26, 2011 5:35 AM

All replies

  • Hi Anup_89,

    Use KeyDown to navigate enter event so that next_click event will be trigger.

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
          if (textBox1.Text != "")
          {
            if (e.KeyCode == Keys.Enter)
            {
              btnNext.Focus();
              btnNext.PerformClick();
            }
          }
        }
    
        private void btnNext_Click(object sender, EventArgs e)
        {
          panel1.Visible = false;
          panel2.Visible = true;
          MessageBox.Show("...");
        }
    


    Hope it helps.

    Thank you.

    Hardz

    • Proposed as answer by RohitArora Tuesday, July 26, 2011 10:30 AM
    • Marked as answer by Helen Zhou Friday, July 29, 2011 7:33 AM
    Tuesday, July 26, 2011 5:35 AM
  • Its simple and works good.
    Monday, August 22, 2011 2:24 AM
  • My laptop wont recognise the perform event or the e.keycode statement
    Wednesday, November 28, 2018 2:51 AM