Hi,
If I have correctly understood your problem, you are trying to populate a textbox (TB3) using the result of the substraction between two integers input (using TB1 and TB2), then you should try the following code snippet:
private void textBox3_MouseClick(object sender, MouseEventArgs e)
{
int a = 0, b = 0, c = 0;
if (!int.TryParse(textBox1.Text,
System.Globalization.NumberStyles.Integer,
System.Globalization.CultureInfo.CurrentUICulture,
out a))
{
MessageBox.Show("enter value");
}
else if (!int.TryParse(textBox2.Text,
System.Globalization.NumberStyles.Integer,
System.Globalization.CultureInfo.CurrentUICulture,
out b))
{
MessageBox.Show("enter value to sub");
}
else
{
c = a - b;
textBox3.Text = c.ToString(
System.Globalization.CultureInfo.CurrentUICulture);
}
}
The TryParse function returns a boolean indicating whether the input string has been parsed into a valid integer. If it returns false, then the out parameter is unchanged from its initial value.
I have used the overload of TryParse that takes in the number style and format provider so that it works on any desktop computer indifferently of its localization (US, European, Russian, Asian, and so on...)
Hope this helps.