Friday

HOW TO CAPTURE ENTER (Return) KEY PRESS EVENT ON TEXTBOX AND INVOKE OTHER EVENTS.....

C# Code....

//first handle KeyDown Event for control on which you want to capture Enter key as follow..

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
//MessageBox.Show("Enter key pressed...");
Invoke(new System.EventHandler(button1_Click)); // Invoking other event handler...
}
}


// Other event which will be indirectly invoked when enter key pressed on TextBox...

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button Clicked");
}




No comments:

Post a Comment

Thanks for visiting my Blog, your message will be notified asap and you will get response accordingly.