Exemple #1
0
 private void devide_Click(Object sender, EventArgs e)
 {
     Operator = (sender as Button).Text;
     try
     {
         Binar_Operators?.Invoke(this, EventArgs.Empty);
     }
     catch
     {
         result_window.Text = "Divide by zero -> hit C";
         foreach (Control item in Controls)
         {
             if (item as Button != null)
             {
                 (item as Button).Enabled = false;
             }
         }
         reset.Enabled = true;
     }
     equals.Focus();
 }
Exemple #2
0
        ///Keys
        private void Form1_KeyDown(Object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Back:
                Backspace?.Invoke(this, EventArgs.Empty);
                equals.Focus();
                break;

            case Keys.Enter:
                Operator = "enter";
                try
                {
                    Controls_op?.Invoke(this, EventArgs.Empty);
                }
                catch
                {
                    result_window.Text = "Divide by zero -> hit C";
                    foreach (Control item in Controls)
                    {
                        if (item as Button != null)
                        {
                            (item as Button).Enabled = false;
                        }
                    }
                    reset.Enabled = true;
                }
                break;

            case Keys.Multiply:
                Operator = "*";
                try
                {
                    Binar_Operators?.Invoke(this, EventArgs.Empty);
                }
                catch
                {
                    result_window.Text = "Divide by zero -> hit C";
                    foreach (Control item in Controls)
                    {
                        if (item as Button != null)
                        {
                            (item as Button).Enabled = false;
                        }
                    }
                    reset.Enabled = true;
                }
                break;

            case Keys.Add:
                Operator = "+";
                try
                {
                    Binar_Operators?.Invoke(this, EventArgs.Empty);
                }
                catch
                {
                    result_window.Text = "Divide by zero -> hit C";
                    foreach (Control item in Controls)
                    {
                        if (item as Button != null)
                        {
                            (item as Button).Enabled = false;
                        }
                    }
                    reset.Enabled = true;
                }
                break;

            case Keys.Subtract:
                Operator = "-";
                try
                {
                    Binar_Operators?.Invoke(this, EventArgs.Empty);
                }
                catch
                {
                    result_window.Text = "Divide by zero -> hit C";
                    foreach (Control item in Controls)
                    {
                        if (item as Button != null)
                        {
                            (item as Button).Enabled = false;
                        }
                    }
                    reset.Enabled = true;
                }
                break;

            case Keys.Decimal:
                try
                {
                    Decimal.Parse("0" + Separator);
                    if (!result_window.Text.Contains(Separator))
                    {
                        result_window.Text += Separator;
                        Digits?.Invoke(this, EventArgs.Empty);
                    }
                    equals.Focus();
                }
                catch
                {
                    Separator = ",";
                    if (!result_window.Text.Contains(Separator))
                    {
                        result_window.Text += Separator;
                        Digits?.Invoke(this, EventArgs.Empty);
                    }
                    equals.Focus();
                }
                break;

            case Keys.Divide:
                Operator = "/";
                try
                {
                    Binar_Operators?.Invoke(this, EventArgs.Empty);
                }
                catch
                {
                    result_window.Text = "Divide by zero -> hit C";
                    foreach (Control item in Controls)
                    {
                        if (item as Button != null)
                        {
                            (item as Button).Enabled = false;
                        }
                    }
                    reset.Enabled = true;
                }
                break;

            default:
                if (e.KeyCode.ToString().StartsWith("NumPad"))
                {
                    result_window.Text += e.KeyCode.ToString().Substring(6);
                    Digits?.Invoke(this, EventArgs.Empty);
                }
                if (e.KeyCode.ToString().StartsWith("D"))
                {
                    result_window.Text += e.KeyCode.ToString().Substring(1);
                    Digits?.Invoke(this, EventArgs.Empty);
                }
                break;
            }
        }