1) modifying the standard behavior of key entry in a Control violates user interface guidelines: it will probably confuse users. 'delete clears the current selection; why deprive the user of that functunality ?
2) You have 4 TextBoxes, assuming 'OnTextChanged is the TextChanged event handler for all 4:
a) if 'txt_Different is used only to display the result of calculations, why allow the user to type in it. consider using a Label.
b) if any of the attempts to parse 'txt_BackedOut, 'txt_TOTAL, 'txt_Online fail, why test 'txt_Different, and possibly change it?
Here's something to help you get started:
private TextBox currentTextBox;
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
currentTextBox = sender as TextBox;
char key = e.KeyChar;
bool allowkey =
(Char.IsNumber(key) || key == '\b')
&&
(currentTextBox.Text.Length > 0 && key != '0');
e.Handled = ! allowkey;
}
This event handler checks each character entered: if the character is a number, or a backspace; then the entry of '0' is prevented if it's the first character. Note that delete is not disabled, and that cut, and paste, are not disabled.
i have strong opinions about how data-entry should be handled/validated in cases like this; i'll be happy to share them, but, first, i'd like to see you consider what i've said here and revise your code.