Exemplo n.º 1
0
 //Backspace Button, Remove Last Char
 private void Back_Click(object sender, RoutedEventArgs e)
 {
     if (!isSecondNumber)
     {
         try
         {
             if (Num.Count() > 1)
             {
                 string pointtest1 = Num.Substring(Num.Count() - 1);
                 if (pointtest1 == ",")
                 {
                     decimal1 = false;
                 }
                 Num = Num.Remove(Num.Count() - 1);
             }
             else
             {
                 Num = "0";
             }
         }
         catch
         {
             ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException();
         }
     }
     else
     {
         try
         {
             if (Num2.Count() > 1)
             {
                 string pointtest2 = Num2.Substring(Num2.Count() - 1);
                 if (pointtest2 == ",")
                 {
                     decimal2 = false;
                 }
                 Num2 = Num2.Remove(Num2.Count() - 1);
             }
             else
             {
                 Num2 = "0";
             }
         }
         catch
         {
             ArgumentNullException ex = new ArgumentNullException();
         }
     }
 }
Exemplo n.º 2
0
        //All Keyboard Hotkeys (Clone Functions inside Window Keydown Method)
        private void Calc_KeyDown(object sender, KeyEventArgs e)
        {
            /*Operation/Function Keys*/
            //Press Backspace Key
            if (e.Key == Key.Back)
            {
                if (!isSecondNumber)
                {
                    try
                    {
                        string pointtest1 = Num.Substring(Num.Count() - 1);
                        if (pointtest1 == ",")
                        {
                            decimal1 = false;
                        }
                        Num = Num.Remove(Num.Count() - 1);
                    }
                    catch
                    {
                        ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    try
                    {
                        string pointtest2 = Num2.Substring(Num2.Count() - 1);
                        if (pointtest2 == ",")
                        {
                            decimal2 = false;
                        }
                        Num2 = Num2.Remove(Num2.Count() - 1);
                    }
                    catch
                    {
                        ArgumentNullException ex = new ArgumentNullException();
                    }
                }
            }
            //Press + Key
            if (e.Key == Key.Add)
            {
                Operation = "+";
                if (!isSecondNumber)
                {
                    isSecondNumber = true;
                    OnPropertyChanged();
                }
                else
                {
                    if (Num2 != null)
                    {
                        Num      = Calc;
                        Num2     = null;
                        decimal1 = false;
                        decimal2 = false;
                        OnPropertyChanged();
                    }
                }
            }
            //Press - Key
            if (e.Key == Key.Subtract)
            {
                Operation = "-";
                if (!isSecondNumber)
                {
                    isSecondNumber = true;
                    OnPropertyChanged();
                }
                else
                {
                    if (Num2 != null)
                    {
                        Num      = Calc;
                        Num2     = null;
                        decimal1 = false;
                        decimal2 = false;
                        OnPropertyChanged();
                    }
                }
            }
            //Press * Key
            if (e.Key == Key.Multiply)
            {
                Operation = "*";
                if (!isSecondNumber)
                {
                    isSecondNumber = true;
                    OnPropertyChanged();
                }
                else
                {
                    if (Num2 != null)
                    {
                        Num  = Calc;
                        Num2 = null;

                        decimal1 = false;
                        decimal2 = false;
                        OnPropertyChanged();
                    }
                }
            }
            //Press / Key
            if (e.Key == Key.Divide)
            {
                Operation = "÷";
                if (!isSecondNumber)
                {
                    isSecondNumber = true;
                    OnPropertyChanged();
                }
                else
                {
                    if (Num2 != null)
                    {
                        Num      = Calc;
                        Num2     = null;
                        decimal1 = false;
                        decimal2 = false;
                        OnPropertyChanged();
                    }
                }
            }
            //Press P Key
            if (e.Key == Key.P)
            {
                Operation = "P";
                if (!isSecondNumber)
                {
                    isSecondNumber = true;
                    OnPropertyChanged();
                }
                else
                {
                    if (Num2 != null)
                    {
                        Num      = Calc;
                        Num2     = null;
                        decimal1 = false;
                        decimal2 = false;
                        OnPropertyChanged();
                    }
                }
            }
            //Press C Key
            if (e.Key == Key.C)
            {
                isSecondNumber = false;
                Num2           = "";
                Num            = "0";
                Operation      = "";
                OnPropertyChanged();
            }
            //Press E Key
            if (e.Key == Key.E)
            {
                if (isSecondNumber)
                {
                    Num2 = "0";
                    OnPropertyChanged();
                }
                else
                {
                    Num = "0";
                    OnPropertyChanged();
                }
            }
            //Press , Key
            if (e.Key == Key.Decimal)
            {
                if (!isSecondNumber)
                {
                    if (!decimal1)
                    {
                        Num     += ",";
                        decimal1 = true;
                        OnPropertyChanged();
                    }
                }
                else
                {
                    if (!decimal2 && Num2 != null)
                    {
                        Num2    += ",";
                        decimal2 = true;
                        OnPropertyChanged();
                    }
                }
            }
            //Press Enter Key
            if (e.Key == Key.Enter)
            {
                if (Num2 != null)
                {
                    Num       = Calc;
                    Num2      = null;
                    Operation = "";
                    decimal1  = false;
                    decimal2  = false;
                    OnPropertyChanged();
                }
            }

            /*Number Keys*/
            //Press 0 Key
            if (e.Key == Key.D0 || e.Key == Key.NumPad0)
            {
                AddNum("0");
            }
            //Press 1 Key
            if (e.Key == Key.D1 || e.Key == Key.NumPad1)
            {
                AddNum("1");
            }
            //Press 2 Key
            if (e.Key == Key.D2 || e.Key == Key.NumPad2)
            {
                AddNum("2");
            }
            //Press 3 Key
            if (e.Key == Key.D3 || e.Key == Key.NumPad3)
            {
                AddNum("3");
            }
            //Press 4 Key
            if (e.Key == Key.D4 || e.Key == Key.NumPad4)
            {
                AddNum("4");
            }
            //Press 5 Key
            if (e.Key == Key.D5 || e.Key == Key.NumPad5)
            {
                AddNum("5");
            }
            //Press 6 Key
            if (e.Key == Key.D6 || e.Key == Key.NumPad6)
            {
                AddNum("6");
            }
            //Press 7 Key
            if (e.Key == Key.D7 || e.Key == Key.NumPad7)
            {
                AddNum("7");
            }
            //Press 8 Key
            if (e.Key == Key.D8 || e.Key == Key.NumPad8)
            {
                AddNum("8");
            }
            //Press 9 Key
            if (e.Key == Key.D9 || e.Key == Key.NumPad9)
            {
                AddNum("9");
            }
        }