Hi, I've been trying to develop a simple calculator, using class, methods, then I'm trying to develop into the main form but somehow I get frustrated and I've erased the code many times, because I'm doubting how to finish it, then this is what I have done. Take a look. I want to do it using only one "TextBox.Text".
Note: I have 3 months programing on Languages, and I really want to learn.
public class Calculator
{
public double Sum(double Variable1,double Variable2){
double ResultSum;
return ResultSum = Variable1 + Variable2;
}
public double Div(double Variable1, double Variable2){
double ResultaDiv;
return ResultaDiv = Variable1 / Variable2;
}
public double Subtra(double Variable1, double Variable2){
double ResultSubtra;
return ResultSubtra = Variable1 - Variable2;
}
public double Mult(double Variable1, double Variable2){
double ResulMult;
return ResulMult = Variable1 * Variable2;
}
}
}
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button7Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7"; // forget this part if you want.
}
void Button8Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}
void Button11Click(object sender, EventArgs e) // This a an operator "/"
{
}
}
}
Loading


Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 11, 2013, 12:56 PM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 11, 2013, 8:14 AM EDT
Freddy Abreu40 reputationPosted Apr 11, 2013, 10:43 AM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 11, 2013, 11:14 AM EDT
What is your idea about using one text box, can you give me an example, is it like in the textbox user will type 1+1 and then click a button and the output will be displayed on a label next to it ?
Freddy Abreu40 reputationPosted Apr 11, 2013, 11:25 AM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 11, 2013, 12:23 PM EDT
correct me if I am wrong:
1. User enters a number in a textbox , textbox text is 1
2. then the user enters the operator, textbox text is 1+
3. then the user enters another number, textbox text is 1+1
4. user presses the = button, the label value is 2
5. user clicks the textbox again, so erase previous value since calculation is done.
is this correct?
Freddy Abreu40 reputationPosted Apr 11, 2013, 12:37 PM EDT
Freddy Abreu40 reputationPosted Apr 12, 2013, 6:53 AM EDT
Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 12, 2013, 6:59 AM EDT
Freddy Abreu40 reputationPosted Apr 12, 2013, 11:30 AM EDT