Event in visual C#
-
Hi, I want to use Keypress event in my windows form. When user press enter that time i want to catch that event. and how to use the keypress event because in visual c# i never seen ASCII keys. Tell me how to catch keypress event and use ASCII values for trap the key which is press by the user. Thank You for Help, (Hemant Uttam Mane)
-
Hi, I want to use Keypress event in my windows form. When user press enter that time i want to catch that event. and how to use the keypress event because in visual c# i never seen ASCII keys. Tell me how to catch keypress event and use ASCII values for trap the key which is press by the user. Thank You for Help, (Hemant Uttam Mane)
Web or Win Form? There are some events and properties in WinForm to see keyboard: KeyPreview, KeyPress, KeyDown etc. See EventArgs and KeyData, KeyChar, KeyCode properties. Hi, AW
-
Hi, I want to use Keypress event in my windows form. When user press enter that time i want to catch that event. and how to use the keypress event because in visual c# i never seen ASCII keys. Tell me how to catch keypress event and use ASCII values for trap the key which is press by the user. Thank You for Help, (Hemant Uttam Mane)
There's many ways of doing this. If you want to catch these in your derivative class, override
OnKeyDown
. External to your class, handle theKeyDown
event. This is to catch and potentially "handle" the key without it being passed to the target window. If you don't care about stopping it from being dispatched, you can handle eitherKeyPress
orKeyUp
. In there, you actually use theKeyEventArgs
- not theEventArgs
like the other response mentioned - to get theKeys
enumeration member for pressed keys, or just the ASCII character value itself. See the documentation for theKeyEventArgs
members for more details. If you want to catch keys throughout your application (say, for configurable hot keys), implement theIMessageFilter
class and add your implementing usingApplication.AddMessageFilter
. You get aMessage
structure that contains the message (such asWM_KEYDOWN
) and you can get the data from theWParam
andLParam
properties. You can also returntrue
to signal that you've handled it and the message should not be dispatched.Microsoft MVP, Visual C# My Articles