Jelmer Posted March 6, 2006 Posted March 6, 2006 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 Quote
Administrators PlausiblyDamp Posted March 6, 2006 Administrators Posted March 6, 2006 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Cags Posted March 6, 2006 Posted March 6, 2006 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... if(e.KeyChar == (char)Keys.Enter) { } For any more help you'll have to answer PlausiblyDamps questions. Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted March 6, 2006 Leaders Posted March 6, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.