How do I suppress the KeyChar in a KeyPress event?

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);
}
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top