Hi..
I have a textbox and two buttons on a form now I want to perform btns event on textbox when I press Enter key from keyboard. so Can I do it.. code like
btnshift_Click(sender, e);
btnsave_Click(sender, e);
any body help.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted May 18, 2011, 5:21 AM
{
if (e.KeyCode == Keys.Enter)
{
//you can call your method here.
btnshift.PerformClick();
btnsave.PerformClick();
}
}
By using button.PerformClick() method,you can inovke the Button.click event Programmatically .
hope this helps you.
Posted May 18, 2011, 5:58 AM
Kanhialal kkPosted May 18, 2011, 5:48 AM
your suggested code is working properly but another problem is there which is when I press enter key than the textbox going to empty and that cause string error! because by save button event that textbox should required some values like numbers...
So??
Posted May 18, 2011, 5:16 AM
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//you can call your method here.
}
}