Keypress - On Enter

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
I like to do something if i press enter in a textfield.. so i found this code:

if(e.KeyChar = Chr(Keys.Enter)){
//my things...
}

But that doesn wordk.. he doesnt know the .keychar and the Chr...
Why not ?????

Or is this for the normal C# and not for C#.Net ??
How to change ?

Thanx,
Jelmer
 
Is this for a windows or web application? Could you clarify what you mean by
doesnt know the .keychar and the Chr
are you getting errors at compile time or runtime - what are the errors?

Also if you are using C# then Chr won't work as that is a VB keyword.
 
KeyChar is only available in the KeyPress event not the KeyUp or KeyDown events. To check if key char is enter then you can do...
C#:
if(e.KeyChar == (char)Keys.Enter) {
}
For any more help you'll have to answer PlausiblyDamps questions.
 
Also, if you consumer the keypress for the enter key (the control reacts to it), make sure that you set e.Handled to true to avoid giving the user an error beep.
 
Back
Top