Define a Dictionary to map TextBoxes to an integer value:
private Dictionary<TextBox, int> TbxToInt;
Put all five TextBoxes in a Panel named 'panel1; in the Form Load event:
private void Form1_Load(object sender, EventArgs e)
{
TbxToInt = new Dictionary<TextBox, int>();
foreach(TextBox tbx in panel1.Controls.OfType<TextBox>())
{
TbxToInt.Add(tbx, 0);
tbx.Text = "0";
}
}
Note all the five TextBoxes all have their initial Text value set to "0:" select all the four TextBoxes for user input in design view, and assign the same 'Leave EventHandler to them:
private void textBox_Leave(object sender, EventArgs e)
{
TextBox tbx = sender as TextBox;
int value = 0;
if (! int.TryParse(tbx.Text, out value))
{
tbx.Text = "0";
}
}
This ensures that only an integer value is displayed.
Left for you to write: the code to scan the Dictionary key-value pairs, and use the integer values in calculation.
Note: I'd handle this by creating a custom component inheriting from TextBox that only let the user type in integer key characters; a more advanced solution: if I showed that, and you used it for a homework assignment, your instructor might be unhappy.