diff options
| author | lempamo <[email protected]> | 2017-02-25 13:36:05 -0500 |
|---|---|---|
| committer | lempamo <[email protected]> | 2017-02-25 13:36:05 -0500 |
| commit | 9aa549e2b99ce4176ccf6dfee705ea25737d360a (patch) | |
| tree | 1c89ab4d8db0dd5f641dd380b7822568580d7bae /ShiftOS.WinForms/Applications | |
| parent | e26453ebeec88dc73636d62785e24871dfbbdb1f (diff) | |
| download | shiftos_thereturn-9aa549e2b99ce4176ccf6dfee705ea25737d360a.tar.gz shiftos_thereturn-9aa549e2b99ce4176ccf6dfee705ea25737d360a.tar.bz2 shiftos_thereturn-9aa549e2b99ce4176ccf6dfee705ea25737d360a.zip | |
Calculator finished
Diffstat (limited to 'ShiftOS.WinForms/Applications')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Calculator.Designer.cs | 55 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/Calculator.cs | 123 |
2 files changed, 167 insertions, 11 deletions
diff --git a/ShiftOS.WinForms/Applications/Calculator.Designer.cs b/ShiftOS.WinForms/Applications/Calculator.Designer.cs index 1f9008e..28db629 100644 --- a/ShiftOS.WinForms/Applications/Calculator.Designer.cs +++ b/ShiftOS.WinForms/Applications/Calculator.Designer.cs @@ -67,6 +67,10 @@ namespace ShiftOS.WinForms.Applications this.buttonPlus = new System.Windows.Forms.Button(); this.buttonMinus = new System.Windows.Forms.Button(); this.buttonMultiply = new System.Windows.Forms.Button(); + this.buttonDivide = new System.Windows.Forms.Button(); + this.buttonC = new System.Windows.Forms.Button(); + this.buttonCE = new System.Windows.Forms.Button(); + this.buttonDecimal = new System.Windows.Forms.Button(); this.SuspendLayout(); // // numBox @@ -208,6 +212,7 @@ namespace ShiftOS.WinForms.Applications this.buttonMinus.TabIndex = 14; this.buttonMinus.Text = "-"; this.buttonMinus.UseVisualStyleBackColor = true; + this.buttonMinus.Click += new System.EventHandler(this.buttonMinus_Click); // // buttonMultiply // @@ -217,11 +222,57 @@ namespace ShiftOS.WinForms.Applications this.buttonMultiply.TabIndex = 15; this.buttonMultiply.Text = "x"; this.buttonMultiply.UseVisualStyleBackColor = true; + this.buttonMultiply.Click += new System.EventHandler(this.buttonMultiply_Click); + // + // buttonDivide + // + this.buttonDivide.Location = new System.Drawing.Point(125, 123); + this.buttonDivide.Name = "buttonDivide"; + this.buttonDivide.Size = new System.Drawing.Size(22, 22); + this.buttonDivide.TabIndex = 16; + this.buttonDivide.Text = "/"; + this.buttonDivide.UseVisualStyleBackColor = true; + this.buttonDivide.Click += new System.EventHandler(this.buttonDivide_Click); + // + // buttonC + // + this.buttonC.Location = new System.Drawing.Point(88, 39); + this.buttonC.Name = "buttonC"; + this.buttonC.Size = new System.Drawing.Size(31, 22); + this.buttonC.TabIndex = 17; + this.buttonC.Text = "C"; + this.buttonC.UseVisualStyleBackColor = true; + this.buttonC.Click += new System.EventHandler(this.buttonC_Click); + // + // buttonCE + // + this.buttonCE.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.buttonCE.Location = new System.Drawing.Point(88, 67); + this.buttonCE.Name = "buttonCE"; + this.buttonCE.Size = new System.Drawing.Size(31, 22); + this.buttonCE.TabIndex = 18; + this.buttonCE.Text = "CE"; + this.buttonCE.UseVisualStyleBackColor = true; + this.buttonCE.Click += new System.EventHandler(this.buttonCE_Click); + // + // buttonDecimal + // + this.buttonDecimal.Location = new System.Drawing.Point(32, 123); + this.buttonDecimal.Name = "buttonDecimal"; + this.buttonDecimal.Size = new System.Drawing.Size(22, 22); + this.buttonDecimal.TabIndex = 19; + this.buttonDecimal.Text = "."; + this.buttonDecimal.UseVisualStyleBackColor = true; + this.buttonDecimal.Click += new System.EventHandler(this.buttonDecimal_Click); // // Calculator // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.buttonDecimal); + this.Controls.Add(this.buttonCE); + this.Controls.Add(this.buttonC); + this.Controls.Add(this.buttonDivide); this.Controls.Add(this.buttonMultiply); this.Controls.Add(this.buttonMinus); this.Controls.Add(this.buttonPlus); @@ -261,5 +312,9 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.Button buttonPlus; private System.Windows.Forms.Button buttonMinus; private System.Windows.Forms.Button buttonMultiply; + private System.Windows.Forms.Button buttonDivide; + private System.Windows.Forms.Button buttonC; + private System.Windows.Forms.Button buttonCE; + private System.Windows.Forms.Button buttonDecimal; } } diff --git a/ShiftOS.WinForms/Applications/Calculator.cs b/ShiftOS.WinForms/Applications/Calculator.cs index c79494f..afd09f5 100644 --- a/ShiftOS.WinForms/Applications/Calculator.cs +++ b/ShiftOS.WinForms/Applications/Calculator.cs @@ -45,6 +45,7 @@ namespace ShiftOS.WinForms.Applications private int activeoperation = 0; private float operationnumber = 0; private float currentnumber = 0; + private bool multiop = false; public Calculator() { @@ -57,6 +58,10 @@ namespace ShiftOS.WinForms.Applications buttonPlus.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_plus_button"); buttonMinus.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_minus_button"); buttonMultiply.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_multiply_button"); + buttonDivide.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_divide_button"); + buttonC.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_clear_button"); + buttonCE.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_ce_button"); + buttonDecimal.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_decimal_button"); } public void OnLoad() @@ -81,57 +86,73 @@ namespace ShiftOS.WinForms.Applications private void numBox_TextChanged(object sender, EventArgs e) { - currentnumber = float.Parse(numBox.Text); + if (numBox.Text.EndsWith(".")) + { + if (numBox.Text == ".") { currentnumber = 0; } + else { currentnumber = float.Parse(numBox.Text.Replace(".", "")); } + } + else if (numBox.Text == "") { currentnumber = 0; } + else { currentnumber = float.Parse(numBox.Text); } } private void button1_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "1"; + if (multiop) { numBox.Text = "1"; multiop = false; } + else { numBox.Text = numBox.Text + "1"; } } private void button2_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "2"; + if (multiop) { numBox.Text = "2"; multiop = false; } + else { numBox.Text = numBox.Text + "2"; } } private void button3_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "3"; + if (multiop) { numBox.Text = "3"; multiop = false; } + else { numBox.Text = numBox.Text + "3"; } } private void button4_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "4"; + if (multiop) { numBox.Text = "4"; multiop = false; } + else { numBox.Text = numBox.Text + "4"; } } private void button5_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "5"; + if (multiop) { numBox.Text = "5"; multiop = false; } + else { numBox.Text = numBox.Text + "5"; } } private void button6_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "6"; + if (multiop) { numBox.Text = "6"; multiop = false; } + else { numBox.Text = numBox.Text + "6"; } } private void button7_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "7"; + if (multiop) { numBox.Text = "7"; multiop = false; } + else { numBox.Text = numBox.Text + "7"; } } private void button8_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "8"; + if (multiop) { numBox.Text = "8"; multiop = false; } + else { numBox.Text = numBox.Text + "8"; } } private void button9_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "9"; + if (multiop) { numBox.Text = "9"; multiop = false; } + else { numBox.Text = numBox.Text + "9"; } } private void button10_Click(object sender, EventArgs e) { - numBox.Text = numBox.Text + "0"; + if (multiop) { numBox.Text = "0"; multiop = false; } + else { numBox.Text = numBox.Text + "0"; } } private void buttonPlus_Click(object sender, EventArgs e) @@ -146,6 +167,7 @@ namespace ShiftOS.WinForms.Applications operationnumber = currentnumber; activeoperation = 1; } + multiop = true; } private void solve() @@ -156,6 +178,18 @@ namespace ShiftOS.WinForms.Applications numBox.Text = (currentnumber + operationnumber).ToString(); break; + case 2: + numBox.Text = (operationnumber - currentnumber).ToString(); + break; + + case 3: + numBox.Text = (operationnumber * currentnumber).ToString(); + break; + + case 4: + numBox.Text = (operationnumber / currentnumber).ToString(); + break; + default: break; } @@ -167,5 +201,72 @@ namespace ShiftOS.WinForms.Applications operationnumber = 0; activeoperation = 0; } + + private void buttonMinus_Click(object sender, EventArgs e) + { + if (operationnumber == 0 && activeoperation == 0) + { + operationnumber = currentnumber; + activeoperation = 2; + } + else + { + solve(); + operationnumber = currentnumber; + activeoperation = 2; + } + multiop = true; + } + + private void buttonMultiply_Click(object sender, EventArgs e) + { + if (operationnumber == 0 && activeoperation == 0) + { + operationnumber = currentnumber; + activeoperation = 3; + } + else + { + solve(); + operationnumber = currentnumber; + activeoperation = 3; + } + multiop = true; + } + + private void buttonDivide_Click(object sender, EventArgs e) + { + if (operationnumber == 0 && activeoperation == 0) + { + operationnumber = currentnumber; + activeoperation = 4; + } + else + { + solve(); + operationnumber = currentnumber; + activeoperation = 4; + } + multiop = true; + } + + private void buttonC_Click(object sender, EventArgs e) + { + numBox.Clear(); + } + + private void buttonCE_Click(object sender, EventArgs e) + { + numBox.Clear(); + operationnumber = 0; + activeoperation = 0; + multiop = false; + } + + private void buttonDecimal_Click(object sender, EventArgs e) + { + if (multiop) { numBox.Text = "."; multiop = false; } + else if (!numBox.Text.Contains(".")) numBox.Text = numBox.Text + "."; + } } } |
