Jarrod Dall Jarrod Dall - 8 months ago 40
C# Question

How to create a click event that will collect the values of multiple text boxes

I have a windows form (C#) with several text boxes. The user will input numeric values for a range of measurements in each one, of possibly 28 text boxes. I would like to create a click event (cmdCalculate) that will simply collect all the values that have been entered, then send them in the form of an argument to a method for the purposes of various calculations in an effort to avoid all the calculations being done with the values directly from the form.

Having trouble with the syntax... when I place all the code for the calculations in the click event all is well, but I have been advised (by an experienced coder) that it is better to collect the values and calculate via a procedure/method...

any help would be appreciated.

public static int cmdCalculate(int one, int two, int three, int four)
{ return one+two+three+four; }

and implement it by

private void button1_Click(object sender, System.EventArgs e)
{ int tempValue = cmdCalculate(textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text); }