diff --git a/Calculadora Forms/Calculadora.Designer.cs b/Calculadora Forms/Calculadora.Designer.cs index b5a4a9f..43b8f9f 100644 --- a/Calculadora Forms/Calculadora.Designer.cs +++ b/Calculadora Forms/Calculadora.Designer.cs @@ -42,13 +42,21 @@ private void InitializeComponent() this.tbOperacao = new System.Windows.Forms.TextBox(); this.btMais = new System.Windows.Forms.Button(); this.btIgual = new System.Windows.Forms.Button(); + this.btMenos = new System.Windows.Forms.Button(); + this.btVezes = new System.Windows.Forms.Button(); + this.btPonto = new System.Windows.Forms.Button(); + this.btSinal = new System.Windows.Forms.Button(); + this.btDividir = new System.Windows.Forms.Button(); + this.btApagar = new System.Windows.Forms.Button(); + this.btLimpar = new System.Windows.Forms.Button(); + this.btReset = new System.Windows.Forms.Button(); this.SuspendLayout(); // // bd1 // - this.bd1.Location = new System.Drawing.Point(80, 330); + this.bd1.Location = new System.Drawing.Point(12, 286); this.bd1.Name = "bd1"; - this.bd1.Size = new System.Drawing.Size(75, 23); + this.bd1.Size = new System.Drawing.Size(75, 48); this.bd1.TabIndex = 0; this.bd1.Text = "1"; this.bd1.UseVisualStyleBackColor = true; @@ -56,91 +64,100 @@ private void InitializeComponent() // // bd2 // - this.bd2.Location = new System.Drawing.Point(187, 330); + this.bd2.Location = new System.Drawing.Point(93, 288); this.bd2.Name = "bd2"; - this.bd2.Size = new System.Drawing.Size(75, 23); + this.bd2.Size = new System.Drawing.Size(75, 48); this.bd2.TabIndex = 1; this.bd2.Text = "2"; this.bd2.UseVisualStyleBackColor = true; + this.bd2.Click += new System.EventHandler(this.bd2_Click); // // bd3 // - this.bd3.Location = new System.Drawing.Point(302, 330); + this.bd3.Location = new System.Drawing.Point(174, 286); this.bd3.Name = "bd3"; - this.bd3.Size = new System.Drawing.Size(75, 23); + this.bd3.Size = new System.Drawing.Size(75, 48); this.bd3.TabIndex = 2; this.bd3.Text = "3"; this.bd3.UseVisualStyleBackColor = true; + this.bd3.Click += new System.EventHandler(this.bd3_Click); // // bd4 // - this.bd4.Location = new System.Drawing.Point(80, 279); + this.bd4.Location = new System.Drawing.Point(12, 235); this.bd4.Name = "bd4"; - this.bd4.Size = new System.Drawing.Size(75, 23); + this.bd4.Size = new System.Drawing.Size(75, 45); this.bd4.TabIndex = 3; this.bd4.Text = "4"; this.bd4.UseVisualStyleBackColor = true; + this.bd4.Click += new System.EventHandler(this.bd4_Click); // // bd5 // - this.bd5.Location = new System.Drawing.Point(187, 279); + this.bd5.Location = new System.Drawing.Point(93, 237); this.bd5.Name = "bd5"; - this.bd5.Size = new System.Drawing.Size(75, 23); + this.bd5.Size = new System.Drawing.Size(75, 46); this.bd5.TabIndex = 4; this.bd5.Text = "5"; this.bd5.UseVisualStyleBackColor = true; + this.bd5.Click += new System.EventHandler(this.bd5_Click); // // bd6 // - this.bd6.Location = new System.Drawing.Point(302, 279); + this.bd6.Location = new System.Drawing.Point(174, 235); this.bd6.Name = "bd6"; - this.bd6.Size = new System.Drawing.Size(75, 23); + this.bd6.Size = new System.Drawing.Size(75, 45); this.bd6.TabIndex = 5; this.bd6.Text = "6"; this.bd6.UseVisualStyleBackColor = true; + this.bd6.Click += new System.EventHandler(this.bd6_Click); // // bd7 // - this.bd7.Location = new System.Drawing.Point(80, 231); + this.bd7.Location = new System.Drawing.Point(12, 187); this.bd7.Name = "bd7"; - this.bd7.Size = new System.Drawing.Size(75, 23); + this.bd7.Size = new System.Drawing.Size(75, 42); this.bd7.TabIndex = 6; this.bd7.Text = "7"; this.bd7.UseVisualStyleBackColor = true; + this.bd7.Click += new System.EventHandler(this.bd7_Click); // // bd8 // - this.bd8.Location = new System.Drawing.Point(187, 231); + this.bd8.Location = new System.Drawing.Point(93, 185); this.bd8.Name = "bd8"; - this.bd8.Size = new System.Drawing.Size(75, 23); + this.bd8.Size = new System.Drawing.Size(75, 46); this.bd8.TabIndex = 7; this.bd8.Text = "8"; this.bd8.UseVisualStyleBackColor = true; + this.bd8.Click += new System.EventHandler(this.bd8_Click); // // bd9 // - this.bd9.Location = new System.Drawing.Point(302, 231); + this.bd9.Location = new System.Drawing.Point(174, 187); this.bd9.Name = "bd9"; - this.bd9.Size = new System.Drawing.Size(75, 23); + this.bd9.Size = new System.Drawing.Size(75, 42); this.bd9.TabIndex = 8; this.bd9.Text = "9"; this.bd9.UseVisualStyleBackColor = true; + this.bd9.Click += new System.EventHandler(this.bd9_Click); // // bd0 // - this.bd0.Location = new System.Drawing.Point(187, 384); + this.bd0.Location = new System.Drawing.Point(93, 342); this.bd0.Name = "bd0"; - this.bd0.Size = new System.Drawing.Size(75, 23); + this.bd0.Size = new System.Drawing.Size(75, 48); this.bd0.TabIndex = 9; this.bd0.Text = "0"; this.bd0.UseVisualStyleBackColor = true; + this.bd0.Click += new System.EventHandler(this.bd0_Click); // // tbDisplay // this.tbDisplay.Anchor = System.Windows.Forms.AnchorStyles.Right; - this.tbDisplay.Location = new System.Drawing.Point(111, 142); + this.tbDisplay.Location = new System.Drawing.Point(12, 59); this.tbDisplay.Name = "tbDisplay"; - this.tbDisplay.Size = new System.Drawing.Size(297, 20); + this.tbDisplay.Size = new System.Drawing.Size(321, 20); this.tbDisplay.TabIndex = 10; this.tbDisplay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.tbDisplay.TextChanged += new System.EventHandler(this.textBox1_TextChanged); @@ -148,36 +165,133 @@ private void InitializeComponent() // tbOperacao // this.tbOperacao.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.tbOperacao.Location = new System.Drawing.Point(111, 112); + this.tbOperacao.Location = new System.Drawing.Point(23, 62); this.tbOperacao.Name = "tbOperacao"; this.tbOperacao.Size = new System.Drawing.Size(88, 13); this.tbOperacao.TabIndex = 11; // // btMais // - this.btMais.Location = new System.Drawing.Point(413, 330); + this.btMais.BackColor = System.Drawing.SystemColors.ActiveBorder; + this.btMais.Location = new System.Drawing.Point(258, 286); this.btMais.Name = "btMais"; - this.btMais.Size = new System.Drawing.Size(75, 23); + this.btMais.Size = new System.Drawing.Size(75, 48); this.btMais.TabIndex = 12; this.btMais.Text = "+"; - this.btMais.UseVisualStyleBackColor = true; + this.btMais.UseVisualStyleBackColor = false; this.btMais.Click += new System.EventHandler(this.btMais_Click); // // btIgual // - this.btIgual.Location = new System.Drawing.Point(413, 384); + this.btIgual.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128))))); + this.btIgual.Location = new System.Drawing.Point(258, 340); this.btIgual.Name = "btIgual"; - this.btIgual.Size = new System.Drawing.Size(75, 23); + this.btIgual.Size = new System.Drawing.Size(75, 48); this.btIgual.TabIndex = 13; this.btIgual.Text = "="; - this.btIgual.UseVisualStyleBackColor = true; + this.btIgual.UseVisualStyleBackColor = false; this.btIgual.Click += new System.EventHandler(this.btIgual_Click); // + // btMenos + // + this.btMenos.BackColor = System.Drawing.SystemColors.ActiveBorder; + this.btMenos.Location = new System.Drawing.Point(258, 235); + this.btMenos.Name = "btMenos"; + this.btMenos.Size = new System.Drawing.Size(75, 46); + this.btMenos.TabIndex = 14; + this.btMenos.Text = "-"; + this.btMenos.UseVisualStyleBackColor = false; + this.btMenos.Click += new System.EventHandler(this.btMenos_Click); + // + // btVezes + // + this.btVezes.BackColor = System.Drawing.SystemColors.ActiveBorder; + this.btVezes.Location = new System.Drawing.Point(258, 187); + this.btVezes.Name = "btVezes"; + this.btVezes.Size = new System.Drawing.Size(75, 42); + this.btVezes.TabIndex = 15; + this.btVezes.Text = "x"; + this.btVezes.UseVisualStyleBackColor = false; + this.btVezes.Click += new System.EventHandler(this.btVezes_Click); + // + // btPonto + // + this.btPonto.Location = new System.Drawing.Point(174, 340); + this.btPonto.Name = "btPonto"; + this.btPonto.Size = new System.Drawing.Size(75, 48); + this.btPonto.TabIndex = 16; + this.btPonto.Text = ","; + this.btPonto.UseVisualStyleBackColor = true; + this.btPonto.Click += new System.EventHandler(this.btPonto_Click); + // + // btSinal + // + this.btSinal.Location = new System.Drawing.Point(12, 340); + this.btSinal.Name = "btSinal"; + this.btSinal.Size = new System.Drawing.Size(75, 48); + this.btSinal.TabIndex = 17; + this.btSinal.Text = "+/-"; + this.btSinal.UseVisualStyleBackColor = true; + this.btSinal.Click += new System.EventHandler(this.btSinal_Click); + // + // btDividir + // + this.btDividir.BackColor = System.Drawing.SystemColors.ActiveBorder; + this.btDividir.Location = new System.Drawing.Point(258, 139); + this.btDividir.Name = "btDividir"; + this.btDividir.Size = new System.Drawing.Size(75, 42); + this.btDividir.TabIndex = 18; + this.btDividir.Text = "/"; + this.btDividir.UseVisualStyleBackColor = false; + this.btDividir.Click += new System.EventHandler(this.btDividir_Click); + // + // btApagar + // + this.btApagar.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.btApagar.Location = new System.Drawing.Point(174, 139); + this.btApagar.Name = "btApagar"; + this.btApagar.Size = new System.Drawing.Size(75, 42); + this.btApagar.TabIndex = 19; + this.btApagar.Text = "Apagar"; + this.btApagar.UseVisualStyleBackColor = false; + this.btApagar.Click += new System.EventHandler(this.btApagar_Click); + // + // btLimpar + // + this.btLimpar.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.btLimpar.Location = new System.Drawing.Point(93, 139); + this.btLimpar.Name = "btLimpar"; + this.btLimpar.Size = new System.Drawing.Size(75, 42); + this.btLimpar.TabIndex = 20; + this.btLimpar.Text = "Limpar"; + this.btLimpar.UseVisualStyleBackColor = false; + this.btLimpar.Click += new System.EventHandler(this.btLimpar_Click); + // + // btReset + // + this.btReset.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.btReset.Location = new System.Drawing.Point(12, 139); + this.btReset.Name = "btReset"; + this.btReset.Size = new System.Drawing.Size(75, 42); + this.btReset.TabIndex = 21; + this.btReset.Text = "Resetar"; + this.btReset.UseVisualStyleBackColor = false; + this.btReset.Click += new System.EventHandler(this.btReset_Click); + // // Calculadora // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(544, 450); + this.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.ClientSize = new System.Drawing.Size(345, 412); + this.Controls.Add(this.btReset); + this.Controls.Add(this.btLimpar); + this.Controls.Add(this.btApagar); + this.Controls.Add(this.btDividir); + this.Controls.Add(this.btSinal); + this.Controls.Add(this.btPonto); + this.Controls.Add(this.btVezes); + this.Controls.Add(this.btMenos); this.Controls.Add(this.btIgual); this.Controls.Add(this.btMais); this.Controls.Add(this.tbOperacao); @@ -215,6 +329,14 @@ private void InitializeComponent() private System.Windows.Forms.TextBox tbOperacao; private System.Windows.Forms.Button btMais; private System.Windows.Forms.Button btIgual; + private System.Windows.Forms.Button btMenos; + private System.Windows.Forms.Button btVezes; + private System.Windows.Forms.Button btPonto; + private System.Windows.Forms.Button btSinal; + private System.Windows.Forms.Button btDividir; + private System.Windows.Forms.Button btApagar; + private System.Windows.Forms.Button btLimpar; + private System.Windows.Forms.Button btReset; } } diff --git a/Calculadora Forms/Calculadora.cs b/Calculadora Forms/Calculadora.cs index 1c24c6b..58ada46 100644 --- a/Calculadora Forms/Calculadora.cs +++ b/Calculadora Forms/Calculadora.cs @@ -12,7 +12,14 @@ namespace Calculadora_Forms { public partial class Calculadora : Form { - bool ordem = true; + bool cond; + + public double valor1; + + public double valor2; + + public int operacao; + public Calculadora() { @@ -24,90 +31,265 @@ private void textBox1_TextChanged(object sender, EventArgs e) } + //Números + private void bd0_Click(object sender, EventArgs e) + { + tbDisplay.Text += "0"; + } + private void bd1_Click(object sender, EventArgs e) { tbDisplay.Text += "1"; } + private void bd2_Click(object sender, EventArgs e) + { + tbDisplay.Text += "2"; + } + + private void bd3_Click(object sender, EventArgs e) + { + tbDisplay.Text += "3"; + } + + private void bd4_Click(object sender, EventArgs e) + { + tbDisplay.Text += "4"; + } + + private void bd5_Click(object sender, EventArgs e) + { + tbDisplay.Text += "5"; + } + + private void bd6_Click(object sender, EventArgs e) + { + tbDisplay.Text += "6"; + } + + private void bd7_Click(object sender, EventArgs e) + { + tbDisplay.Text += "7"; + } + + private void bd8_Click(object sender, EventArgs e) + { + tbDisplay.Text += "8"; + } + + private void bd9_Click(object sender, EventArgs e) + { + tbDisplay.Text += "9"; + } + + //Funções das operações + private void btMais_Click(object sender, EventArgs e) { Calculos obj = new Calculos(); - obj.operacao = 1; + operacao = 1; - if(obj.valor1 == 0) //Erro aqui, assim o valor vai ser sempre 0 pois ele é inserido só dentro do if + if(valor1 == 0) { tbOperacao.Text = tbDisplay.Text + " +"; - obj.valor1 = int.Parse(tbDisplay.Text); + valor1 = double.Parse(tbDisplay.Text); + tbDisplay.Text = ""; + } + else + { + btIgual_Click(sender, e); + } + } + + private void btMenos_Click(object sender, EventArgs e) + { + Calculos obj = new Calculos(); + + operacao = 2; + + if (valor1 == 0) + { + tbOperacao.Text = tbDisplay.Text + " -"; + valor1 = double.Parse(tbDisplay.Text); + tbDisplay.Text = ""; } else { btIgual_Click(sender, e); } + } + + private void btVezes_Click(object sender, EventArgs e) + { + Calculos obj = new Calculos(); + + operacao = 3; + + if (valor1 == 0) + { + tbOperacao.Text = tbDisplay.Text + " x"; + valor1 = double.Parse(tbDisplay.Text); + tbDisplay.Text = ""; + } + else + { + btIgual_Click(sender, e); + } + } + private void btDividir_Click(object sender, EventArgs e) + { + Calculos obj = new Calculos(); + + operacao = 4; + + if (valor1 == 0) + { + tbOperacao.Text = tbDisplay.Text + " /"; + valor1 = double.Parse(tbDisplay.Text); + tbDisplay.Text = ""; + } + else + { + btIgual_Click(sender, e); + } + } + + //Funções auxiliares + + private void btReset_Click(object sender, EventArgs e) + { + tbDisplay.Text = ""; + tbOperacao.Text = ""; + valor1 = 0; + valor2 = 0; + } + + private void btLimpar_Click(object sender, EventArgs e) + { tbDisplay.Text = ""; } + private void btApagar_Click(object sender, EventArgs e) + { + string displayCompl = ""; + + for (int i = 0; i < tbDisplay.Text.Length - 1; i++) + { + displayCompl += tbDisplay.Text[i]; + } + + tbDisplay.Text = displayCompl; + } + + private void btSinal_Click(object sender, EventArgs e) + { + if (tbDisplay.Text[0] == '-') + { + string displayCompl = ""; + + for (int i = 1; i < tbDisplay.Text.Length; i++) + { + displayCompl += tbDisplay.Text[i]; + } + + tbDisplay.Text = displayCompl; + } + else + { + string modificado = tbDisplay.Text.Insert(0, "-"); + tbDisplay.Text = modificado; + } + } + + private void btPonto_Click(object sender, EventArgs e) + { + cond = false; + + for (int i = 0; i < tbDisplay.Text.Length; i++) + { + if (tbDisplay.Text[i] == ',') + { + cond = true; + MessageBox.Show("Insira apenas uma vírgula"); + } + } + + if (cond == false) + { + tbDisplay.Text += ","; + } + } + + //Função igual + private void btIgual_Click(object sender, EventArgs e) { Calculos obj = new Calculos(); - obj.valor2 = int.Parse(tbDisplay.Text); + double result = 0; - switch (obj.operacao) + if(tbDisplay.Text == "") + { + MessageBox.Show("Insira um valor"); + } + else { - case 1: - tbDisplay.Text = obj.Soma().ToString(); - break; + valor2 = double.Parse(tbDisplay.Text); - case 2: - tbDisplay.Text = obj.Sub().ToString(); - break; + switch (operacao) + { + case 1: + result = obj.Soma(valor1, valor2); + break; - case 3: - tbDisplay.Text = obj.Multi().ToString(); - break; + case 2: + result = obj.Sub(valor1, valor2); + break; - case 4: - tbDisplay.Text = obj.Divi().ToString(); - break; + case 3: + result = obj.Multi(valor1, valor2); + break; - default: - MessageBox.Show("Insira uma operação para o cálculo"); - break; - } + case 4: + result = obj.Divi(valor1, valor2); + break; - obj.valor1 = 0; - obj.valor2 = 0; - obj.operacao = 0; - tbOperacao.Text = ""; + default: + MessageBox.Show("Insira uma operação para o cálculo"); + break; + } + + tbDisplay.Text = result.ToString(); + valor1 = 0; + valor2 = 0; + operacao = 0; + tbOperacao.Text = ""; + } } + } class Calculos { - public double valor1; - - public double valor2; - - public int operacao; - public double Soma() + public double Soma(double valor1, double valor2) { return valor1 + valor2; } - public double Sub() + public double Sub(double valor1, double valor2) { return valor1 - valor2; } - public double Multi() + public double Multi(double valor1, double valor2) { return valor1 * valor2; } - public double Divi() + public double Divi(double valor1, double valor2) { if(valor1 == 0 || valor2 == 0) { diff --git a/README.md b/README.md index 9a9d6ba..4804949 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# Calculadora Forms \ No newline at end of file +# Calculadora Forms + +Branch de testes e desenvolvimento