diff --git a/Calculator.csproj b/Calculator.csproj new file mode 100644 index 0000000..663fdb8 --- /dev/null +++ b/Calculator.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/Calculator.sln b/Calculator.sln new file mode 100644 index 0000000..66c2099 --- /dev/null +++ b/Calculator.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36414.22 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator", "Calculator.csproj", "{04B58D4E-36B2-418A-A659-94302139B2C3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04B58D4E-36B2-418A-A659-94302139B2C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04B58D4E-36B2-418A-A659-94302139B2C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04B58D4E-36B2-418A-A659-94302139B2C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04B58D4E-36B2-418A-A659-94302139B2C3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3F072D0C-4641-4596-A8EA-29E684F64857} + EndGlobalSection +EndGlobal diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..3d8083d --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,292 @@ +namespace Calculator +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + btn_input_6 = new Button(); + btn_input_3 = new Button(); + btn_input_5 = new Button(); + btn_input_2 = new Button(); + btn_input_8 = new Button(); + btn_input_9 = new Button(); + btn_input_7 = new Button(); + btn_input_4 = new Button(); + btn_input_1 = new Button(); + btn_input_0 = new Button(); + btn_input_comma = new Button(); + lbl_main = new Label(); + btn_input_add = new Button(); + btn_input_sub = new Button(); + btn_input_div = new Button(); + btn_input_mult = new Button(); + btn_import_prev = new Button(); + lbl_number = new Label(); + btn_next = new Button(); + SuspendLayout(); + // + // btn_input_6 + // + btn_input_6.Location = new Point(444, 149); + btn_input_6.Name = "btn_input_6"; + btn_input_6.Size = new Size(71, 34); + btn_input_6.TabIndex = 4; + btn_input_6.Text = "6"; + btn_input_6.UseVisualStyleBackColor = true; + btn_input_6.Visible = false; + // + // btn_input_3 + // + btn_input_3.Location = new Point(444, 109); + btn_input_3.Name = "btn_input_3"; + btn_input_3.Size = new Size(71, 34); + btn_input_3.TabIndex = 10; + btn_input_3.Text = "3"; + btn_input_3.UseVisualStyleBackColor = true; + btn_input_3.Visible = false; + // + // btn_input_5 + // + btn_input_5.Location = new Point(367, 149); + btn_input_5.Name = "btn_input_5"; + btn_input_5.Size = new Size(71, 34); + btn_input_5.TabIndex = 11; + btn_input_5.Text = "5"; + btn_input_5.UseVisualStyleBackColor = true; + btn_input_5.Visible = false; + // + // btn_input_2 + // + btn_input_2.Location = new Point(367, 109); + btn_input_2.Name = "btn_input_2"; + btn_input_2.Size = new Size(71, 34); + btn_input_2.TabIndex = 12; + btn_input_2.Text = "2"; + btn_input_2.UseVisualStyleBackColor = true; + btn_input_2.Visible = false; + // + // btn_input_8 + // + btn_input_8.Location = new Point(367, 189); + btn_input_8.Name = "btn_input_8"; + btn_input_8.Size = new Size(71, 34); + btn_input_8.TabIndex = 13; + btn_input_8.Text = "8"; + btn_input_8.UseVisualStyleBackColor = true; + btn_input_8.Visible = false; + // + // btn_input_9 + // + btn_input_9.Location = new Point(444, 189); + btn_input_9.Name = "btn_input_9"; + btn_input_9.Size = new Size(71, 34); + btn_input_9.TabIndex = 14; + btn_input_9.Text = "9"; + btn_input_9.UseVisualStyleBackColor = true; + btn_input_9.Visible = false; + // + // btn_input_7 + // + btn_input_7.Location = new Point(290, 189); + btn_input_7.Name = "btn_input_7"; + btn_input_7.Size = new Size(71, 34); + btn_input_7.TabIndex = 15; + btn_input_7.Text = "7"; + btn_input_7.UseVisualStyleBackColor = true; + btn_input_7.Visible = false; + // + // btn_input_4 + // + btn_input_4.Location = new Point(290, 149); + btn_input_4.Name = "btn_input_4"; + btn_input_4.Size = new Size(71, 34); + btn_input_4.TabIndex = 16; + btn_input_4.Text = "4"; + btn_input_4.UseVisualStyleBackColor = true; + btn_input_4.Visible = false; + // + // btn_input_1 + // + btn_input_1.Location = new Point(290, 109); + btn_input_1.Name = "btn_input_1"; + btn_input_1.Size = new Size(71, 34); + btn_input_1.TabIndex = 17; + btn_input_1.Text = "1"; + btn_input_1.UseVisualStyleBackColor = true; + btn_input_1.Visible = false; + // + // btn_input_0 + // + btn_input_0.Location = new Point(332, 229); + btn_input_0.Name = "btn_input_0"; + btn_input_0.Size = new Size(71, 34); + btn_input_0.TabIndex = 18; + btn_input_0.Text = "0"; + btn_input_0.UseVisualStyleBackColor = true; + btn_input_0.Visible = false; + // + // btn_input_comma + // + btn_input_comma.Location = new Point(409, 229); + btn_input_comma.Name = "btn_input_comma"; + btn_input_comma.Size = new Size(71, 34); + btn_input_comma.TabIndex = 20; + btn_input_comma.Text = ","; + btn_input_comma.UseVisualStyleBackColor = true; + btn_input_comma.Visible = false; + // + // lbl_main + // + lbl_main.Anchor = AnchorStyles.Top; + lbl_main.AutoSize = true; + lbl_main.Location = new Point(347, 40); + lbl_main.Name = "lbl_main"; + lbl_main.Size = new Size(121, 25); + lbl_main.TabIndex = 21; + lbl_main.Text = "Välj operation"; + lbl_main.TextAlign = ContentAlignment.TopCenter; + // + // btn_input_add + // + btn_input_add.Location = new Point(347, 137); + btn_input_add.Name = "btn_input_add"; + btn_input_add.Size = new Size(56, 34); + btn_input_add.TabIndex = 22; + btn_input_add.Text = "+"; + btn_input_add.UseVisualStyleBackColor = true; + // + // btn_input_sub + // + btn_input_sub.Location = new Point(409, 137); + btn_input_sub.Name = "btn_input_sub"; + btn_input_sub.Size = new Size(56, 34); + btn_input_sub.TabIndex = 23; + btn_input_sub.Text = "-"; + btn_input_sub.UseVisualStyleBackColor = true; + // + // btn_input_div + // + btn_input_div.Location = new Point(409, 177); + btn_input_div.Name = "btn_input_div"; + btn_input_div.Size = new Size(56, 34); + btn_input_div.TabIndex = 24; + btn_input_div.Text = "/"; + btn_input_div.UseVisualStyleBackColor = true; + // + // btn_input_mult + // + btn_input_mult.Location = new Point(347, 177); + btn_input_mult.Name = "btn_input_mult"; + btn_input_mult.Size = new Size(56, 34); + btn_input_mult.TabIndex = 25; + btn_input_mult.Text = "*"; + btn_input_mult.UseVisualStyleBackColor = true; + // + // btn_import_prev + // + btn_import_prev.Location = new Point(55, 149); + btn_import_prev.Name = "btn_import_prev"; + btn_import_prev.Size = new Size(164, 88); + btn_import_prev.TabIndex = 26; + btn_import_prev.Text = "Importera föregÃ¥ende svar"; + btn_import_prev.UseVisualStyleBackColor = true; + btn_import_prev.Visible = false; + btn_import_prev.Click += btn_import_prev_Click; + // + // lbl_number + // + lbl_number.Anchor = AnchorStyles.Top; + lbl_number.AutoSize = true; + lbl_number.Location = new Point(347, 65); + lbl_number.Name = "lbl_number"; + lbl_number.Size = new Size(0, 25); + lbl_number.TabIndex = 27; + lbl_number.TextAlign = ContentAlignment.TopCenter; + // + // btn_next + // + btn_next.Location = new Point(584, 149); + btn_next.Name = "btn_next"; + btn_next.Size = new Size(125, 72); + btn_next.TabIndex = 28; + btn_next.Text = "Nästa"; + btn_next.UseVisualStyleBackColor = true; + btn_next.Visible = false; + // + // Form1 + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(btn_next); + Controls.Add(lbl_number); + Controls.Add(btn_import_prev); + Controls.Add(btn_input_mult); + Controls.Add(btn_input_div); + Controls.Add(btn_input_sub); + Controls.Add(btn_input_add); + Controls.Add(lbl_main); + Controls.Add(btn_input_comma); + Controls.Add(btn_input_0); + Controls.Add(btn_input_1); + Controls.Add(btn_input_4); + Controls.Add(btn_input_7); + Controls.Add(btn_input_9); + Controls.Add(btn_input_8); + Controls.Add(btn_input_2); + Controls.Add(btn_input_5); + Controls.Add(btn_input_3); + Controls.Add(btn_input_6); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + public Button btn_input_6; + public Button btn_input_3; + public Button btn_input_5; + public Button btn_input_2; + public Button btn_input_8; + public Button btn_input_9; + public Button btn_input_7; + public Button btn_input_4; + public Button btn_input_1; + public Button btn_input_0; + public Button btn_input_comma; + public Label lbl_main; + public Button btn_input_add; + public Button btn_input_sub; + public Button btn_input_div; + public Button btn_input_mult; + public Button btn_import_prev; + public Label lbl_number; + public Button btn_next; + } +} diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..fed90d2 --- /dev/null +++ b/Form1.cs @@ -0,0 +1,15 @@ +namespace Calculator +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void btn_import_prev_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..4606d37 --- /dev/null +++ b/Program.cs @@ -0,0 +1,177 @@ +using System.Diagnostics.Eventing.Reader; +using System.Windows.Forms; + +namespace Calculator +{ + internal static class Program + { + static Form1 form = new Form1(); + static double valueA; + static double valueB; + static bool isSecondNumber = false; + static bool answerGiven = false; + static bool hasStoredAnwser = false; + static double lastAnswer; + static Operator selectedOperator; + + enum Operator + { + Add, + Sub, + Mult, + Div + } + + static void Main() + { + ApplicationConfiguration.Initialize(); + InitButtons(); + StartSelection(); + Application.Run(form); + } + + static private void InitButtons() + { + form.btn_input_0.Click += RegisterInput; + form.btn_input_1.Click += RegisterInput; + form.btn_input_2.Click += RegisterInput; + form.btn_input_3.Click += RegisterInput; + form.btn_input_4.Click += RegisterInput; + form.btn_input_5.Click += RegisterInput; + form.btn_input_6.Click += RegisterInput; + form.btn_input_7.Click += RegisterInput; + form.btn_input_8.Click += RegisterInput; + form.btn_input_9.Click += RegisterInput; + + form.btn_input_add.Click += SelectAdd; + form.btn_input_sub.Click += SelectSub; + form.btn_input_mult.Click += SelectMult; + form.btn_input_div.Click += SelectDiv; + + form.btn_next.Click += Next; + form.btn_import_prev.Click += ImportPrevious; + } + + + static private void ShowOperators(bool value) + { + form.btn_input_add.Visible = value; + form.btn_input_sub.Visible = value; + form.btn_input_mult.Visible = value; + form.btn_input_div.Visible = value; + } + + static private void ShowNumbers(bool value) + { + form.btn_input_0.Visible = value; + form.btn_input_1.Visible = value; + form.btn_input_2.Visible = value; + form.btn_input_3.Visible = value; + form.btn_input_4.Visible = value; + form.btn_input_5.Visible = value; + form.btn_input_6.Visible = value; + form.btn_input_7.Visible = value; + form.btn_input_8.Visible = value; + form.btn_input_9.Visible = value; + form.btn_import_prev.Visible = value; + } + + static private void SelectAdd(object sender, EventArgs e) + { + OperatorSelected(Operator.Add); + } + static private void SelectSub(object sender, EventArgs e) + { + OperatorSelected(Operator.Sub); + } + static private void SelectMult(object sender, EventArgs e) + { + OperatorSelected(Operator.Mult); + } + static private void SelectDiv(object sender, EventArgs e) + { + OperatorSelected(Operator.Div); + } + + static private void OperatorSelected(Operator operation) + { + form.lbl_main.Text = "Ange tal 1"; + ShowOperators(false); + ShowNumbers(true); + selectedOperator = operation; + form.btn_next.Visible = false; + } + + static private void StartSelection() + { + ShowOperators(true); + isSecondNumber = false; + answerGiven = false; + form.lbl_main.Text = "Välj operation"; + form.btn_import_prev.Enabled = hasStoredAnwser; + } + + static private void RegisterInput(object sender, EventArgs e) + { + if (sender is Button b) + { + form.lbl_number.Text += b.Text; + form.btn_next.Visible = true; + } + } + + static private void ImportPrevious(object sender, EventArgs e) + { + form.lbl_number.Text += lastAnswer.ToString(); + form.btn_next.Visible = true; + } + + static private void Next(object sender, EventArgs e) + { + if (answerGiven) + { + StartSelection(); + return; + } + + if (!isSecondNumber) + { + valueA = double.Parse(form.lbl_number.Text); + form.lbl_main.Text = "Ange tal 2"; + isSecondNumber = true; + form.btn_next.Visible = false; + } + else + { + valueB = double.Parse(form.lbl_number.Text); + Answer(); + isSecondNumber = false; + } + form.lbl_number.Text = ""; + } + + static private void Answer() + { + double value = 0; + + ShowOperators(false); + ShowNumbers(false); + + if (selectedOperator == Operator.Add) + value = valueA + valueB; + else if (selectedOperator == Operator.Sub) + value = valueA - valueB; + else if (selectedOperator == Operator.Mult) + value = valueA * valueB; + else if (selectedOperator == Operator.Div) + value = valueA / valueB; + + hasStoredAnwser = true; + lastAnswer = value; + form.btn_import_prev.Text = "Importera föregående svar" + " (" + value.ToString() + ")"; + + form.lbl_main.Text = "Ditt tal är " + value.ToString(); + answerGiven = true; + } + } +} \ No newline at end of file