Esempio n. 1
0
 private void Sub_Click(object sender, EventArgs e)
 {
     Equal.Focus();
     if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
     {
         Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
     }
     if (Equasion.Text.Equals("0"))
     {
         Equasion.ResetText();
     }
     Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "-");
 }
Esempio n. 2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Equal.Focus();
            if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up || e.KeyCode == Keys.Right || e.KeyCode == Keys.Down)
            {
                Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
            }
            Text = Convert.ToString(e.KeyValue);
            if (e.Modifiers == Keys.Enter)
            {
                Answer.Text = Calculate(Equasion.Text);
                if (Answer.Text == "ERROR")
                {
                    return;
                }
                Equasion.Text = Answer.Text;
            }

            if (e.Shift)
            {
                switch (e.KeyValue)
                {
                case 27:
                    Close();
                    break;

                case 187:
                    if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/"))
                    {
                        Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                    }
                    Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "*");
                    return;

                case 55:
                    if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/"))
                    {
                        Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                    }
                    Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "/");
                    return;
                }
            }

            switch (e.KeyValue)
            {
            case 48:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "0");
                break;

            case 49:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "1");
                break;

            case 50:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "2");
                break;

            case 51:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "3");
                break;

            case 52:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "4");
                break;

            case 53:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "5");
                break;

            case 54:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "6");
                break;

            case 55:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "7");
                break;

            case 56:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "8");
                break;

            case 57:
                if (Equasion.Text == "0")
                {
                    Equasion.Text = "";
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "9");
                break;

            case 187:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "+");
                break;

            case 107:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "+");
                break;

            case 189:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "-");
                break;

            case 109:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                if (Equasion.Text.Equals("0"))
                {
                    Equasion.ResetText();
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "-");
                break;

            case 106:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "*");
                break;

            case 111:
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
                {
                    Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "/");
                break;

            case 188:
                if (Equasion.Text.Split(new char[] { '+', '-', '*', '/' })[(Equasion.Text.Split(new char[] { '+', '-', '*', '/' }).Length - 1)].Contains(","))
                {
                    return;
                }
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/"))
                {
                    Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "0");
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, ",");
                break;

            case 190:
                if (Equasion.Text.Split(new char[] { '+', '-', '*', '/' })[(Equasion.Text.Split(new char[] { '+', '-', '*', '/' }).Length - 1)].Contains(","))
                {
                    return;
                }
                if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/"))
                {
                    Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "0");
                }
                Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, ",");
                break;

            case 27:
                WindowState = FormWindowState.Minimized;
                break;

            case 46:
                Equasion.Text = "0";
                break;

            case 8:
                if (Equasion.Text.Length == 1)
                {
                    Equasion.Text = "0";
                    return;
                }
                Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
                break;
            }
        }