I tried this code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13)
{
MessageBox.S
Try this:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.Key.ToString())
{
case "Return":
MessageBox.Show(" Enter pressed ");
break;
}
}
You must try this in keydown event
here is the code for that :
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
MessageBox.Show("Enter pressed");
}
}
Update :
Also you can do this with keypress event.
Try This :
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Return))
{
MessageBox.Show("Key pressed");
}
}
private void Input_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
MessageBox.Show("Enter pressed");
}
}
This worked for me.
Keeping in mind that
Keys.Return is different to Keys.Enter
//Makes it easier to Type user and password and press Enter,
//Rather than using the mouse to Click the Button all the time
private void Txt_Password_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Return)
{
Btn_Login_Click(null, null);
}
}
Hope this help someone.
Also you can do this with keypress event.
private void textBox1_EnterKeyPress(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// some code what you wanna do
}
}
private void Ctrl_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.SelectNextControl((Control)sender, true, true, true, true);
}
}
Select all required textboxes; type in new Events name Ctrl_KeyUp.
See YouTube by BTNT TV: https://www.bing.com/videos/searchq=c%23+how+to+move+to+next+textbox+after+enterkey&view=detail&mid=999E8CAFC15140E867C0999E8CAFC15140E867C0&FORM=VIRE