Solved Closed

C# How to do a math operation with one button and one text box?

This is for school.

I want to be able to able to type a number into a text box click a button, then type another number into the same text box click a button and apply a math operation to those two numbers(In visual studio 2010 C#). Now, I don't have any trouble with the math operations, but I have no idea how to prepare for it. We have only been taught to do the operations when there were multiple boxes, by storing the values into a variable converting it, adding the two integers then converting back. I thought maybe using arrays? But we have only been taught if then statements,while loops, and bools.

This is what I have. We need to show the number of values that were put in, which is why I have number++;

public partial class frmtemp : Form

int number=0;

public frmtemp()

private void frmtemp_Load(object sender, EventArgs e)


private void txt1_TextChanged(object sender, EventArgs e)


private void frmtemp_FormClosing(object sender, FormClosingEventArgs e)

MessageBox.Show("Numbers Added: "+number.ToString());

this.DialogResult = DialogResult.OK;


private void btntemp_Click(object sender, EventArgs e)

5 answers Last reply Best Answer
More about math operation button text
  1. Yup, school has started and now here come the "please do my assignment for me" posts.
  2. oh sorry didn't want to come off like that, at this point I just want to know if it is possible using bools,while loops, and if then statements.
  3. Best answer
    An array is the cleanest way to do it.
  4. thanks
  5. Best answer selected by austinedwards7.
Ask a new question

Read More

Programming C# Visual Studio Apps