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

Re: What does the KeyPressEventsArgs handle property do? by Stoitcho

Stoitcho
Tue Feb 28 08:09:59 CST 2006

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.


--
HTH
Stoitcho Goutsev (100)

"rsine" <rsine@stationeryhouse.com> wrote in message
news:1141134822.059193.209810@p10g2000cwp.googlegroups.com...
>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
>