This can't be simply done using the
TextChanged
event because changing the content would raise the event again.
It is common to use another text box to show the result or provide a button to perform the calculation.
You should also use the
Int32.TryParse Method (String, Int32) (System)[
^] to handle invalid input.
If you still want to use the same box, you have to use a guarding variable:
bool selfUpdate = false;
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!selfUpdate)
{
int x;
if (Int32.TryParse(textBox1.Text, out x))
{
x *= 350;
selfUpdate = true;
textBox1.Text = x.ToString();
selfUpdate = false;
}
}
}
[EDIT]
But note that when using the above each change will update so that only single digits can be entered or text must be pasted.
[/EDIT]