How do I suppress the KeyChar in a KeyPress event?

  • Thread starter Thread starter Top Gun
  • Start date Start date
T

Top Gun

I am trying to trap on a keypress "+" event and convert it to a tab for a
high-speed dataentry form that is done entirely from a 10-key. However, I do
NOT want the "+" character to be passed on to the textbox.

I am using code similar to this:

public class FastEntryControl : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ( (char)'+' == e.KeyChar )
//This is to create the tab event... but the "+" is still being entered
into the current textbox before the tab
base.OnKeyPress( new KeyPressEventArgs ( '\t');
else
base.OnKeyPress( e);
}
 
Top Gun said:
I am trying to trap on a keypress "+" event and convert it to a tab for a
high-speed dataentry form that is done entirely from a 10-key. However, I do
NOT want the "+" character to be passed on to the textbox.

Set e.Handled to true to suppress further processing of the event.
 
Back
Top