I tried this code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13)
{
MessageBox.S
private void textBoxKontant_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
MessageBox.Show("Enter pressed");
}
}
Screenshot:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
MessageBox.Show("Enter Key Pressed");
}
}
This allows you to choose the specific Key you want, without finding the char value of the key.
For me, this was the best solution:
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
MessageBox.Show("Enter key pressed");
}
}
Instead of using Key_press event you may use Key_down event. You can find this as below
after double clicking here it will automatically this code
private void textbox1_KeyDown(object sender, KeyEventArgs e)
{
}
Problem solved now use as you want.
private void textbox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show(" Enter pressed ");
}
}
Try this code,might work (Assuming windows form):
private void CheckEnter(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
// Enter key pressed
}
}
Register the event like this :
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(CheckEnter);
private void TextBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("Enter pressed");
}
}
Worked for me.