prevent special keychars from being displayed in a textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi NG,
in my app I want to capture different keychars in a textbox so that they are
not displayed. That is because I want to react to these keychars with special
code.
I want to choose for this for example the keychar "\" and I think therefore
I can not take the keycode.
That works well, but the keychars are then dipplayed in the textbox.
How can I make the keychar not to be displayed?

Select Case e.KeyChar
Case "\"

End Select

Thanks for any idea!

Werner
 
Add an event handler to the KeyPress event of the TextBox and after you've
detected a character that you want to treat as special set the Handled
property of the KeyPressEventArgs to True. Here's some C# code, that should
be easily translated to VB.NET.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
switch (e.KeyChar)
{
case '\\':
{
// Do something.
e.Handled = true;
break;
}
}
}
 
Back
Top