I might suggest you start practicing some better coding practices. The sooner you do it right, the less difficult it is to unlearn bad habits.
Like don't use the textbox as a place to
store information. That's what variable and properties are for. Textboxes are pretty GUI things for
displaying information.
Make a decimal property with get and set methods. When someone sets a value to the decimal property, it's set method can then update the textbox.
- decimal _runningtotal;
-
decimal RunningTotal
-
{
-
get
-
{
-
return _runningtotal;
-
}
-
set
-
{
-
_runningtotal = value;
-
if (tbTotalTextbox != null)
-
{
-
tbTotalTextbox.Text = _runningtotal.ToString();
-
}
-
}
-
}
Now anywhere else in your code you have a decimal variable you can work with, instead of constantly converting your Textbox.Text for every calculation
Second. Don't use textboxes for strict numeric input since you then after keep validating the user input isn't "cat" instead of '4'. Use a NumericUpDown. The user can still type a number, and you can turn off the up/down spin controls in the properties of the of control so it looks like a textbox, but only accepts numbers and you can set minimum and maximum acceptable values.