Freddy Abreu

Freddy Abreu

  • NA
  • 40
  • 9.1k

Simple calculator (Windows Forms)

Apr 11 2013 9:20 AM
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 "/"
 {
 
 }
 }

Answers (10)