aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications
diff options
context:
space:
mode:
authorAren <[email protected]>2017-02-25 19:44:56 +0100
committerGitHub <[email protected]>2017-02-25 19:44:56 +0100
commited5b6549369d470f8aaafbae7716081448377369 (patch)
treecd43f2b8e9292e8ae486bbe51d1be3bee51ed6b3 /ShiftOS.WinForms/Applications
parent68828baafd981c35d3858dedd5c42114eab612c7 (diff)
parent9aa549e2b99ce4176ccf6dfee705ea25737d360a (diff)
downloadshiftos_thereturn-ed5b6549369d470f8aaafbae7716081448377369.tar.gz
shiftos_thereturn-ed5b6549369d470f8aaafbae7716081448377369.tar.bz2
shiftos_thereturn-ed5b6549369d470f8aaafbae7716081448377369.zip
Merge pull request #92 from lempamo/master
calc finished
Diffstat (limited to 'ShiftOS.WinForms/Applications')
-rw-r--r--ShiftOS.WinForms/Applications/Calculator.Designer.cs96
-rw-r--r--ShiftOS.WinForms/Applications/Calculator.cs166
2 files changed, 251 insertions, 11 deletions
diff --git a/ShiftOS.WinForms/Applications/Calculator.Designer.cs b/ShiftOS.WinForms/Applications/Calculator.Designer.cs
index c97c754..28db629 100644
--- a/ShiftOS.WinForms/Applications/Calculator.Designer.cs
+++ b/ShiftOS.WinForms/Applications/Calculator.Designer.cs
@@ -64,6 +64,13 @@ namespace ShiftOS.WinForms.Applications
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.buttonEquals = new System.Windows.Forms.Button();
+ 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
@@ -75,6 +82,7 @@ namespace ShiftOS.WinForms.Applications
this.numBox.ReadOnly = true;
this.numBox.Size = new System.Drawing.Size(143, 30);
this.numBox.TabIndex = 0;
+ this.numBox.TextChanged += new System.EventHandler(this.numBox_TextChanged);
//
// button1
//
@@ -184,11 +192,90 @@ namespace ShiftOS.WinForms.Applications
this.buttonEquals.TabIndex = 12;
this.buttonEquals.Text = "=";
this.buttonEquals.UseVisualStyleBackColor = true;
+ this.buttonEquals.Click += new System.EventHandler(this.buttonEquals_Click);
+ //
+ // buttonPlus
+ //
+ this.buttonPlus.Location = new System.Drawing.Point(125, 39);
+ this.buttonPlus.Name = "buttonPlus";
+ this.buttonPlus.Size = new System.Drawing.Size(22, 22);
+ this.buttonPlus.TabIndex = 13;
+ this.buttonPlus.Text = "+";
+ this.buttonPlus.UseVisualStyleBackColor = true;
+ this.buttonPlus.Click += new System.EventHandler(this.buttonPlus_Click);
+ //
+ // buttonMinus
+ //
+ this.buttonMinus.Location = new System.Drawing.Point(125, 67);
+ this.buttonMinus.Name = "buttonMinus";
+ this.buttonMinus.Size = new System.Drawing.Size(22, 22);
+ this.buttonMinus.TabIndex = 14;
+ this.buttonMinus.Text = "-";
+ this.buttonMinus.UseVisualStyleBackColor = true;
+ this.buttonMinus.Click += new System.EventHandler(this.buttonMinus_Click);
+ //
+ // buttonMultiply
+ //
+ this.buttonMultiply.Location = new System.Drawing.Point(125, 95);
+ this.buttonMultiply.Name = "buttonMultiply";
+ this.buttonMultiply.Size = new System.Drawing.Size(22, 22);
+ 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);
this.Controls.Add(this.buttonEquals);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
@@ -202,7 +289,7 @@ namespace ShiftOS.WinForms.Applications
this.Controls.Add(this.button1);
this.Controls.Add(this.numBox);
this.Name = "Calculator";
- this.Size = new System.Drawing.Size(171, 176);
+ this.Size = new System.Drawing.Size(166, 185);
this.ResumeLayout(false);
this.PerformLayout();
@@ -222,5 +309,12 @@ namespace ShiftOS.WinForms.Applications
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button buttonEquals;
+ 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 eb2df29..afd09f5 100644
--- a/ShiftOS.WinForms/Applications/Calculator.cs
+++ b/ShiftOS.WinForms/Applications/Calculator.cs
@@ -42,6 +42,10 @@ namespace ShiftOS.WinForms.Applications
public partial class Calculator : UserControl, IShiftOSWindow
{
public bool justopened = false;
+ private int activeoperation = 0;
+ private float operationnumber = 0;
+ private float currentnumber = 0;
+ private bool multiop = false;
public Calculator()
{
@@ -51,6 +55,13 @@ namespace ShiftOS.WinForms.Applications
private void prepareButtons()
{
buttonEquals.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_equals_button");
+ 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()
@@ -73,54 +84,189 @@ namespace ShiftOS.WinForms.Applications
prepareButtons();
}
+ private void numBox_TextChanged(object sender, EventArgs e)
+ {
+ 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)
+ {
+ if (operationnumber == 0 && activeoperation == 0)
+ {
+ operationnumber = currentnumber;
+ activeoperation = 1;
+ } else
+ {
+ solve();
+ operationnumber = currentnumber;
+ activeoperation = 1;
+ }
+ multiop = true;
+ }
+
+ private void solve()
+ {
+ switch (activeoperation)
+ {
+ case 1:
+ 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;
+ }
+ }
+
+ private void buttonEquals_Click(object sender, EventArgs e)
+ {
+ solve();
+ 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 + ".";
}
}
}