managing Deletes and Backspaces
-
I am writing a textbox validator control how would I check to see if the person presses the backspace button and the delete button and then tell windows not to process those messages as I will do it all myself ------------------ I'm naked under my clothes...
-
I am writing a textbox validator control how would I check to see if the person presses the backspace button and the delete button and then tell windows not to process those messages as I will do it all myself ------------------ I'm naked under my clothes...
Simple. Just handle the
KeyDown
event. Check theKeyCode
that is passed to you on theKeyEventArgs
forKeys.Delete
orKeys.Back
. If those are set, setHandled
totrue
:myTextBox.KeyDown += new KeyEventHandler(myTextbox_KeyDown);
//...
private void myTextBox_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete);
// Execute your code instead. When finished, Windows will not perform
// the default action.
}Microsoft MVP, Visual C# My Articles