Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to get focus from one text box to another using keyboard keys not by mouse click .so I wrote the code but it doesn't work. It shows some error. The code is:
C#
private void keypressHandler(object sender, KeyPressEventArgs e) {
if (e.KeyChar == Keys.Enter) {
SendKeys.SendWait("{TAB}");
}
}  

The error I get is:
operator==cannot be applied to operands of type 'char' and System.windows.forms.keys"

How can I remove the error? If it's a wrong way then give correct code.
Posted
Updated 21-Nov-10 22:56pm
v2

1 solution

Instead of 'e.KeyChar == Keys.Enter' try:
e.KeyChar == 11

See this page for details: KeyChar values[^]

Thus, something like:
C#
if (e.KeyChar.Equals(Convert.ToChar(11)))
{
    SendKeys.SendWait("{TAB}");
}
 
Share this answer
 
Comments
Dalek Dave 22-Nov-10 5:07am    
Good Call.
Toniyo Jackson 22-Nov-10 5:33am    
Good answer
shakil0304003 22-Nov-10 5:52am    
Good Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900