weird keypress problem

  • Thread starter Thread starter Lasse Edsvik
  • Start date Start date
L

Lasse Edsvik

Hello

I have this code in my project and it doesnt work, what might be wrong?

private void Textbox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)

{

if (e.KeyChar == '\n')

{

Textbox2.Text = "KKK";

Textbox1.Text = "";

}

}



nothing happens :( no errors when compiling either......



any ideas?

/Lasse
 
Alternatively, you could try hooking into the KeyDown event...

private void Textbox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
...
}
}

If you wish to compare with a char, you can cast the Keys enumeration to a
Char. Your original issue would have been that you wanted '\r' anyway. For
readability, I suggest:

char Enter = (char)Keys.Enter;
 
Back
Top