Created
December 11, 2017 18:28
-
-
Save kien-ngo/c14fd632fc6f5420548c2c40eee608c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Windows.Forms; | |
| namespace WindowsFormsApp1 | |
| { | |
| public partial class Form1 : Form | |
| { | |
| static double total=0; | |
| static double temp; | |
| static bool isPlused = false; | |
| static bool isMinus = false; | |
| static bool isMultiplied = false; | |
| static bool isDivided = false; | |
| static bool isFacted = false; | |
| static bool isPowered = false; | |
| static bool isSquared = false; | |
| public Form1() | |
| { | |
| InitializeComponent(); | |
| buttonSqrt.Text = "\u221A"; | |
| buttonReset.Enabled = false; | |
| } | |
| #region Reset-QuadraticFormular | |
| private void pictureBox1_Click(object sender, EventArgs e) | |
| { | |
| buttonReset.Enabled = true; | |
| panel2.Hide(); | |
| panel1.Show(); | |
| panel3.Enabled = false; | |
| label1.Text = "Reza is handsome"; | |
| label1.Enabled = true; | |
| } | |
| private void buttonReset_Click(object sender, EventArgs e) | |
| { | |
| panel1.Hide(); | |
| panel2.Show(); | |
| foreach (Control c in this.Controls) | |
| { | |
| c.Enabled = true ; | |
| } | |
| textBoxA.Clear(); | |
| textBoxB.Clear(); | |
| textBoxC.Clear(); | |
| labelX1.Text = "X1 ="; | |
| labelX2.Text = "X2 ="; | |
| label1.Text = ""; | |
| buttonReset.Enabled = false; | |
| } | |
| private void buttoncalc_Click(object sender, EventArgs e) | |
| { | |
| double a = double.Parse(textBoxA.Text); | |
| double b = double.Parse(textBoxB.Text); | |
| double c = double.Parse(textBoxC.Text); | |
| double delta = Math.Pow(b, 2) - 4 * a * c; | |
| if (delta==0) | |
| { | |
| labelX1.Text += Convert.ToString(-b / (2 * a)); | |
| labelX2.Text += Convert.ToString(-b / (2 * a)); | |
| } | |
| else | |
| { | |
| if (delta > 0) | |
| { | |
| labelX1.Text += Convert.ToString((-b - Math.Sqrt(delta)) / (2 * a)); | |
| labelX2.Text += Convert.ToString((-b + Math.Sqrt(delta)) / (2 * a)); | |
| } | |
| else | |
| { | |
| MessageBox.Show("There is no solution for this equation!"); | |
| }; | |
| } | |
| } | |
| #endregion | |
| #region x^2, x! and sqrt(x) | |
| private void buttonS1_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Text += "!"; | |
| isPlused = false; | |
| isMinus = false; | |
| isMultiplied = false; | |
| isDivided = false; | |
| isFacted = true; | |
| isPowered = false; | |
| isSquared = false; | |
| } | |
| else | |
| { } | |
| } | |
| private void buttonPower2_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Text += "^2"; | |
| isPlused = false; | |
| isMinus = false; | |
| isMultiplied = false; | |
| isDivided = false; | |
| isFacted = false; | |
| isPowered = true; | |
| isSquared = false; | |
| } | |
| else | |
| { | |
| } | |
| } | |
| private void buttonSqrt_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text = "\u221A" + textBox1.Text; | |
| isPlused = false; | |
| isMinus = false; | |
| isMultiplied = false; | |
| isDivided = false; | |
| isFacted = false; | |
| isPowered = false; | |
| isSquared = true; | |
| } | |
| #endregion | |
| #region 0-9 | |
| private void button0_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button0.Text; | |
| } | |
| private void button1_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button1.Text; | |
| } | |
| private void button2_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button2.Text; | |
| } | |
| private void button3_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button3.Text; | |
| } | |
| private void button4_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button4.Text; | |
| } | |
| private void button5_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button5.Text; | |
| } | |
| private void button6_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button6.Text; | |
| } | |
| private void button7_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button7.Text; | |
| } | |
| private void button8_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button8.Text; | |
| } | |
| private void button9_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text += button9.Text; | |
| } | |
| #endregion | |
| #region Settings | |
| private void buttonDel_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Clear(); | |
| } | |
| private void buttondot_Click(object sender, EventArgs e) | |
| { | |
| MessageBox.Show("No function for this yet, sorry ^^"); | |
| } | |
| private void buttone_Click(object sender, EventArgs e) | |
| { | |
| MessageBox.Show("No function for this yet, sorry ^^"); | |
| } | |
| private void button10_Click(object sender, EventArgs e) | |
| { | |
| textBox1.Text=textBox1.Text.Substring(0, textBox1.Text.Length - 1); | |
| } | |
| private void textBox1_TextChanged(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length == 0) | |
| button10.Enabled = false; | |
| else | |
| button10.Enabled = true; | |
| } | |
| #endregion | |
| #region Equal Button | |
| private void buttonEqual_Click(object sender, EventArgs e) | |
| { | |
| if (isPlused == true) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Text = Convert.ToString(total); | |
| total = 0; | |
| } | |
| else if (isMinus == true) | |
| { | |
| total = total - double.Parse(textBox1.Text); | |
| textBox1.Text = Convert.ToString(total); | |
| total = 0; | |
| } | |
| else if (isMultiplied == true) | |
| { | |
| total = total * double.Parse(textBox1.Text); | |
| textBox1.Text = Convert.ToString(total); | |
| total = 0; | |
| } | |
| else if (isDivided == true) | |
| { | |
| total = total / double.Parse(textBox1.Text); | |
| textBox1.Text = Convert.ToString(total); | |
| total = 0; | |
| } | |
| else if (isFacted == true) | |
| { | |
| for (double i = total - 1; i > 0; i--) | |
| { | |
| total = total * i; | |
| }; | |
| textBox1.Text = Convert.ToString(total); | |
| total = 0; | |
| } | |
| else if (isPowered == true) | |
| { | |
| textBox1.Text = Convert.ToString(Math.Pow(total, 2)); | |
| total = 0; | |
| } | |
| else if (isSquared == true) | |
| { | |
| textBox1.Text=textBox1.Text.Remove(0, 1); | |
| total = double.Parse(textBox1.Text); | |
| textBox1.Text = Convert.ToString(Math.Sqrt(total)); | |
| total = 0; | |
| } | |
| } | |
| #endregion | |
| #region + - x / | |
| private void buttonX_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Clear(); | |
| isPlused = false; | |
| isMinus = false; | |
| isMultiplied = true; | |
| isDivided = false; | |
| isFacted = false; | |
| isPowered = false; | |
| isSquared = false; | |
| } | |
| else { } | |
| } | |
| private void buttonDiv_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Clear(); | |
| isPlused = false; | |
| isMinus = false; | |
| isMultiplied = false; | |
| isDivided = true; | |
| isFacted = false; | |
| isPowered = false; | |
| isSquared = false; | |
| } | |
| else { } | |
| } | |
| private void buttonAdd_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Clear(); | |
| isPlused = true; | |
| isMinus = false; | |
| isMultiplied = false; | |
| isDivided = false; | |
| isFacted = false; | |
| isPowered = false; | |
| isSquared = false; | |
| } | |
| else { } | |
| } | |
| private void buttonSub_Click(object sender, EventArgs e) | |
| { | |
| if (textBox1.Text.Length != 0) | |
| { | |
| total = total + double.Parse(textBox1.Text); | |
| textBox1.Clear(); | |
| isPlused = false; | |
| isMinus = true; | |
| isMultiplied = false; | |
| isDivided = false; | |
| isFacted = false; | |
| isPowered = false; | |
| isSquared = false; | |
| } | |
| else { } | |
| } | |
| #endregion | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment