New keyboard APIs: KeyEventArgs.SuppressKeyPress

Here's the scenario:

In 1.1 whenever someone types one character you want to replace it with another. (If you're thinking password textbox there's a TextBox.UseSystemPassword=true flag you should use).

So you sync TextBox KeyDown, set handled to true and tack on some placeholder * at the end.

 private void textBox1_KeyDown(object sender, KeyEventArgs e) {
e.Handled = true;
textBox1.Text += "*";
}

The problem is that "Handled" doesn't take care of pending WM_CHAR messages already built up in the message queue - so setting Handled = true does not prevent a KeyPress from occurring.

In order not to break anyone who has currently got e.Handled = true, we needed to add a new property called SuppressKeyChar. If we went the other way, if "handling" a keydown suddenly started to actually work, we might break folks who accidentally had this set to true.

The new code?

private void textBox1_KeyDown(object sender, KeyEventArgs e) {
e.SuppressKeyPress = true;
textBox1.Text += "*";
}

[Edit 8:43PM - technical correction - thanks Matt!]