What does the KeyPressEventsArgs handle property do?

  • Thread starter Thread starter rsine
  • Start date Start date
R

rsine

I am trying to understand exactly what the handle property of the
KeyPressEventsArgs does. I thought I could set it to false to prevent
a key from being included into a textbox. For example, if I wanted
only numbers in my textbox and the user pressed an alpha character key,
then I would set the handle property to false and it would be as if the
KeyPress event never occurred thus negating the keystroke. However,
what I am seeing is the pressed key still ends up in my textbox. I
read on MSDN that if the handle is set to false, the operating system
uses a default process to handle the event which is what I figure is
putting the keystroke into the textbox. Is this true or am I
misreading what happens? If it is true, what does setting the handle
property to false actually do?

-Thanks
 
rsine,

You almost got it. You need to set the Handled (past tense) property to
*true* if you want to indicate that you have processed the keypress and you
don't want the framework to do its default processing - putting the
character into the textbox.
 
Back
Top