By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

weird keypress problem

P: n/a
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


Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Lasse,
the solve is e.KeyChar == (char)13

pronojit

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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


Nov 15 '05 #2

P: n/a
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;

--
Regards,
Matt
ma*********@iinet.net.au
"Pronojit Roy" <pr*********@hotmail.com> wrote in message
news:eC**************@TK2MSFTNGP09.phx.gbl...
Hi Lasse,
the solve is e.KeyChar == (char)13

pronojit

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
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



Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.