Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to typecast this KeyPress?

C#
if (e.eyChar = Keys.S)
            {
                timer1.Stop();
            }


Error:
MSIL
Error   1   Cannot implicitly convert type 'System.Windows.Forms.Keys' to 'char'. An explicit conversion exists (are you missing a cast?)
Posted
Updated 10-Oct-10 18:46pm
v3
Comments
DaveAuld 10-Oct-10 10:05am    
You dropped a K and an = in your code, see the answer below for a working code and cast op.

This should do the trick. Don't forget the '==' instead of your '=' ;)

if (e.KeyChar == (char)Keys.S)
{
}
 
Share this answer
 
v2
C#
if (e.KeyChar == (char) Keys.S)
 {
     MessageBox.Show(e.KeyChar.ToString());
 }
 
Share this 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