In my program i have several texboxes and buttons with coresponding names (ex. TextBox1 – buttonPlus1) like on the picture

but there are filled with numbers loaded from text file.
I want to write function that allows me to press button + and enlarge (add fixed number, for example 100) value from textbox. So far i have done:
private void buttonPlus1_Click(object sender, EventArgs e)
{
AddValue(sender,e);
}
private void AddValue(object sender, EventArgs e)
{
if (!(sender is Button))
return;
string controlName = (sender as Button).Name;
string textBoxName = controlName.Replace("buttonPlus", "textBox");
TextBox textBox = this.Controls.Find(textBoxName, false)[0] as TextBox;
int step = 100;
}
but i have no idea how to take value (as number) from textBox and add that step. Can somebody please help me? I tried to solve it by myself in many different ways, but it does not work
Get the value:
Save it to a variable, add 100 and just set it as usual.
P.S. You can also use
Int32.Parse("")(You might need to
.ToString()it)EDIT:
As ltiong_sh mentioned, you should use TryParse rather then Parse: