1 – 1 of 1
Blogger Yakko Warner said...

Addendum: Apparently, you should also be aware that, in a KeyDown event, setting the Handled property of the event args doesn't actually suppress the key; you also want to set the SuppressKeyPress flag.

If you want a low-level explanation, this blog post (and the comments therein) seem to suggest it has to do with a difference in the way Windows Forms queues and/or handles window messages.

The high-level view, though: if you don't SuppressKeyPress, you may end up wondering why the heck your TextBoxes beep at you when you tab out of them. Then you might, say, turn your text box into a multi-line to see what happens, notice it's getting a tab character inserted into its text area, and wonder why Handled isn't handling it; which, if you're lucky, will eventually have to stumbling upon the SuppressKeyPress property, which might send you googling for an answer as to why there's a second property that does what the first one is supposed to, but doesn't. (Note the sample code in the MSDN article that seems to suggest Handled aborts a key press, even though the Remarks suggest it doesn't, although for the life of me I can't figure out why it shouldn't besides they just made it so.)

10 June, 2009 12:34

Your civil comments are appreciated. Thanks!
You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot