Exemplo n.º 1
0
        private void BtnDifferences_Click(object sender, EventArgs e)
        {
            for (int r = 1; r <= 12; r++)
            {
                for (int c = 1; c <= 4; c++)
                {
                    Difference[r, c] = Violations[r, c, 2] - Violations[r, c, 1];
                }
            }

            TxtDisplay.Clear();
            TxtDisplay.Text  = "Change in Violations from 1982 to 1983" + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            TxtDisplay.Text += "\t";

            for (int c = 1; c <= 4; c++)
            {
                TxtDisplay.Text += TicketType[c] + "\t";
            }

            TxtDisplay.Text += Environment.NewLine;

            for (int r = 1; r <= 12; r++)
            {
                TxtDisplay.Text += Months[r] + "\t";
                for (int c = 1; c <= 4; c++)
                {
                    TxtDisplay.Text += Convert.ToString(Difference[r, c]) + "\t";
                }
                TxtDisplay.Text += Environment.NewLine;
            }

            TxtDisplay.Text += Environment.NewLine;
        }
Exemplo n.º 2
0
        private void BtnDisplay_Click(object sender, EventArgs e)
        {
            TxtDisplay.Clear();
            TxtDisplay.Text  = "Parking Violations Summary" + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            for (int slice = 1; slice <= 2; slice++)
            {
                TxtDisplay.Text += Year[slice] + "\t";

                for (int c = 1; c <= 4; c++)
                {
                    TxtDisplay.Text += TicketType[c] + "\t";
                }

                TxtDisplay.Text += Environment.NewLine;

                for (int r = 1; r <= 12; r++)
                {
                    TxtDisplay.Text += Months[r] + "\t";
                    for (int c = 1; c <= 4; c++)
                    {
                        TxtDisplay.Text += Convert.ToString(Violations[r, c, slice]) + "\t";
                    }
                    TxtDisplay.Text += Environment.NewLine;
                }

                TxtDisplay.Text += Environment.NewLine;
            }
        }
Exemplo n.º 3
0
        private void Display(string[,] m, int rows, int cols, string [] w, int u, string text)
        {
            TxtDisplay.Clear();
            TxtDisplay.Text += text + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            TxtDisplay.Text += "Words to Find" + Environment.NewLine;

            for (int i = 1; i <= u; i++)
            {
                TxtDisplay.Text += w[i] + Environment.NewLine;
            }

            TxtDisplay.Text += Environment.NewLine;
            TxtDisplay.Text += "Puzzle" + Environment.NewLine;


            for (int r = 1; r <= rows; r++)
            {
                for (int c = 1; c <= cols; c++)
                {
                    TxtDisplay.Text += Convert.ToString(m[r, c]);
                }
                TxtDisplay.Text += Environment.NewLine;
            }

            TxtDisplay.Text += Environment.NewLine;
        }
Exemplo n.º 4
0
        private void BtnPalindrome_Click(object sender, EventArgs e)
        {
            TxtDisplay.Clear();

            string StartUpPath = Application.StartupPath;
            string f           = StartUpPath + @"\palindromes.txt";

            StreamReader r = new StreamReader(f);

            string line;
            bool   finished = false;

            while (!finished)
            {
                line = r.ReadLine();

                if (line == null)
                {
                    finished = true;
                }
                else
                {
                    if (isPalindrome(Strip(line))) //note here how  we have embedded a method inside another method
                    {
                        TxtDisplay.Text += line + " YES" + Environment.NewLine;
                    }
                    else
                    {
                        TxtDisplay.Text += line + " NO" + Environment.NewLine;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void DisplayResults(string[] c, string[] ag, int[,] v, int[] ct, int g)
        {
            TxtDisplay.Clear();
            TxtDisplay.Text  = "Questionnaire Analysis" + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            TxtDisplay.Text += "\t";

            for (int a = 1; a <= 2; a++)
            {
                TxtDisplay.Text += ag[a] + "\t";
            }

            TxtDisplay.Text += "Total";

            TxtDisplay.Text += Environment.NewLine;

            for (int r = 1; r <= 3; r++)
            {
                TxtDisplay.Text += c[r] + "\t";
                for (int a = 1; a <= 2; a++)
                {
                    TxtDisplay.Text += Convert.ToString(v[r, a]) + "\t";
                }

                TxtDisplay.Text += ct[r];

                TxtDisplay.Text += Environment.NewLine;
            }

            TxtDisplay.Text += "\t" + "\t" + "\t" + g.ToString();
        }
Exemplo n.º 6
0
        private void BtnDisplayFriends_Click(object sender, EventArgs e)
        {
            string StartUpPath = Application.StartupPath;
            string f           = StartUpPath + @"\friends.txt";

            StreamReader r = new StreamReader(f);

            string line;
            string contents = "";
            bool   finished = false;

            while (!finished)
            {
                line = r.ReadLine();
                if (line == null)
                {
                    finished = true;
                }
                else
                {
                    contents += line + Environment.NewLine;
                }
            }

            r.Close();
            TxtDisplay.Clear();
            TxtDisplay.Text = contents;
        }
        private void Display(StudentRecord[] rec, int u)
        {
            TxtDisplay.Clear();

            for (int i = 1; i <= u; i++)
            {
                TxtDisplay.Text += rec[i].sname + "\t" + rec[i].mark + Environment.NewLine;
            }
        }
        private void BtnCheapestPath_Click(object sender, EventArgs e)
        {
            DataFile(grid, ref gridXrow, ref gridYcolumn);
            TxtDisplay.Clear();
            Display(grid, gridXrow, gridYcolumn, "Original Grid");

            cheapest = 10000;

            BestPath(gridXrow, 1, grid[gridXrow, 1], "" + grid[gridXrow, 1]);

            TxtDisplay.Text += "The cheapest path is: " + cheapest.ToString("c") + ".- through " + path;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Event that happens when a number button is clicked
        /// Inserts a number into the equation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NumbersEvent(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (TxtDisplay.Text == "0" || _entered_value)
            {
                TxtDisplay.Clear();
            }

            TxtDisplay.Text  += btn.Text;
            _entered_value    = false;
            _operatorInserted = false;
        }
Exemplo n.º 10
0
        private void BtnCount_Click(object sender, EventArgs e)
        {
            TxtDisplay.Clear();

            string StartUpPath = Application.StartupPath;
            string f           = StartUpPath + @"\words.txt";

            StreamReader r = new StreamReader(f);

            string word;
            string line;

            int cases = int.Parse(r.ReadLine());

            //The tricky part of this problem is the case insensitive
            //matching, you can convert the input word and sentence to both upper
            //or lower case,although you must save a copy of the original word
            //because it is required in the output

            for (int i = 1; i <= cases; i++)
            {
                word = r.ReadLine();
                line = r.ReadLine().ToLower();

                string cmpWord = word.ToLower();

                int count = 0;

                int index = line.IndexOf(cmpWord);

                while (index != -1)
                {
                    count++;
                    index = line.IndexOf(cmpWord, index + 1);
                }


                TxtDisplay.Text += word + Environment.NewLine;
                TxtDisplay.Text += line + Environment.NewLine;
                TxtDisplay.Text += "Occurences of the word -> " + word + " is " + count + Environment.NewLine + Environment.NewLine;
            }
        }
Exemplo n.º 11
0
        private void BtnBegin_Click(object sender, EventArgs e)
        {
            DataFile(grid, ref rows, ref cols);

            TxtDisplay.Clear();

            Display(grid, rows, cols, "Original Grid");
            TxtDisplay.Text += "Starting position is row: " + startrow.ToString() + " column :" + startcolumn.ToString() + Environment.NewLine;
            TxtDisplay.Text += "Ending position is row: " + endrow.ToString() + " column :" + endcolumn.ToString() + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            if (FindPath(startrow, startcolumn))
            {
                TxtDisplay.Text += "Goal Reached !!" + Environment.NewLine;
                Display(grid, rows, cols, "Here is the Path");
            }
            else
            {
                TxtDisplay.Text += "Goal not reached";
            }
        }
Exemplo n.º 12
0
        private void BtnDisplayNewFriends_Click(object sender, EventArgs e)
        {
            string StartUpPath = Application.StartupPath;
            string f           = StartUpPath + @"\newfriends.txt";

            StreamReader r = new StreamReader(f);

            string line;
            string contents = "";


            while ((line = r.ReadLine()) != null)
            {
                contents += line + Environment.NewLine;
            }

            r.Close();

            TxtDisplay.Clear();
            TxtDisplay.Text = contents;
        }
Exemplo n.º 13
0
        private void PasteClick(object sender, RoutedEventArgs e)
        {
            string savedText = TxtDisplay.Text;

            TxtDisplay.Clear();
            Regex regex = new Regex("[+-]?[0-9]||[0-9][.0-9]||[0-9][,0-9]");

            if (regex.IsMatch(Clipboard.GetText()) == true)
            {
                TxtDisplay.Paste();
                if (TxtDisplay.Text.Contains(".") == true)
                {
                    BtnPoint.IsEnabled = false;
                }
            }
            else
            {
                MessageBox.Show("Invalid input!");
                TxtDisplay.Text = savedText;
            }
        }
Exemplo n.º 14
0
        private void DisplayRecords()
        {
            TxtDisplay.Clear();
            TxtDisplay.Text  = "Business" + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            TxtDisplay.Text += "Name" + "\t" + "\t" + "Telephone" + "\t" + "Occupation";
            TxtDisplay.Text += Environment.NewLine;

            for (int r = 1; r <= n; r++)
            {
                for (int c = 1; c <= 3; c++)
                {
                    TxtDisplay.Text += (BusRec[r, c]) + "\t" + "\t";
                }
                TxtDisplay.Text += Environment.NewLine;
            }

            TxtDisplay.Text += Environment.NewLine;
            TxtDisplay.Refresh();
        }
Exemplo n.º 15
0
        private void DisplayCensusResults(string [] a, string [] s, int [,] c, int [] at, int [] st, int g)
        {
            TxtDisplay.Clear();
            TxtDisplay.Text  = "Census Analysis" + Environment.NewLine;
            TxtDisplay.Text += Environment.NewLine;

            TxtDisplay.Text += "\t";

            for (int i = 1; i <= 2; i++)
            {
                TxtDisplay.Text += s[i] + "\t";
            }

            TxtDisplay.Text += "Total";

            TxtDisplay.Text += Environment.NewLine;

            for (int i = 1; i <= 8; i++)
            {
                TxtDisplay.Text += a[i] + "\t";
                for (int j = 1; j <= 2; j++)
                {
                    TxtDisplay.Text += Convert.ToString(c[i, j]) + "\t";
                }

                TxtDisplay.Text += at[i];

                TxtDisplay.Text += Environment.NewLine;
            }

            TxtDisplay.Text += "Total" + "\t";

            for (int j = 1; j <= 2; j++)
            {
                TxtDisplay.Text += st[j] + "\t";
            }

            TxtDisplay.Text += g.ToString();
        }
Exemplo n.º 16
0
        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            if ((TxtDisplay.Text == "0" || (operationChecked)))
            {
                TxtDisplay.Clear();
            }
            operationChecked = false;
            Button button = sender as Button;

            if (memoryClicked == true)
            {
                TxtDisplay.Text = button.Content.ToString();
            }
            else
            {
                TxtDisplay.Text = TxtDisplay.Text + button.Content.ToString();
                FormatTextForClick(sender);
            }
            EnableDisableButtons(true);
            BtnEqual.IsEnabled = true;
            BtnC.IsEnabled     = true;
            BtnCE.IsEnabled    = true;
        }
Exemplo n.º 17
0
        private void BtnMarks_Click(object sender, EventArgs e)
        {
            TxtDisplay.Clear();
            contents = "";
            total    = 0;
            counter  = 0;
            average  = 0;


            string StartUpPath = Application.StartupPath;
            string f           = StartUpPath + @"\marks.txt";

            StreamReader r = new StreamReader(f);

            bool finished = false;

            while (!finished)
            {
                ReadData(r);

                if (studentname == null || studentmark == null)
                {
                    finished = true;
                }
                else
                {
                    Math();
                }
            }

            r.Close();

            average = total / counter;

            TxtDisplay.Text = contents + Environment.NewLine + "Overall Average is " + average.ToString("n2");;
        }
Exemplo n.º 18
0
 private void KeyboardKeyDown(object sender, KeyEventArgs e)
 {
     if (TxtDisplay.Text != "0" && GetDigit(e) != null && operationChecked == false)
     {
         TxtDisplay.Text += GetDigit(e);
         if (digitGroupingCheck == true)
         {
             string decimalPart = "";
             if (TxtDisplay.Text.Contains(".") == true)
             {
                 decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
             }
             int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
             string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
             if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
             {
                 changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
             }
             if (TxtDisplay.Text.Contains("."))
             {
                 changedDisplay += decimalPart;
             }
             if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
             {
                 changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
             }
             if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
             {
                 changedDisplay += "0";
             }
             TxtDisplay.Text = changedDisplay;
         }
         else
         {
             double number = double.Parse(TxtDisplay.Text);
             TxtDisplay.Text = number.ToString("G");
         }
         EnableDisableButtons(true);
         BtnEqual.IsEnabled = true;
         BtnC.IsEnabled     = true;
         BtnCE.IsEnabled    = true;
     }
     else if (TxtDisplay.Text == "0" && GetDigit(e) != null)
     {
         TxtDisplay.Text = GetDigit(e);
         if (digitGroupingCheck == true)
         {
             string decimalPart = "";
             if (TxtDisplay.Text.Contains(".") == true)
             {
                 decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
             }
             int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
             string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
             if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
             {
                 changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
             }
             if (TxtDisplay.Text.Contains("."))
             {
                 changedDisplay += decimalPart;
             }
             if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
             {
                 changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
             }
             if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
             {
                 changedDisplay += "0";
             }
             TxtDisplay.Text = changedDisplay;
         }
         else
         {
             double number = double.Parse(TxtDisplay.Text);
             TxtDisplay.Text = number.ToString("G");
         }
         EnableDisableButtons(true);
         BtnEqual.IsEnabled = true;
         BtnC.IsEnabled     = true;
         BtnCE.IsEnabled    = true;
     }
     else if (TxtDisplay.Text != "0" && GetDigit(e) != null && operationChecked == true)
     {
         TxtDisplay.Text  = GetDigit(e);
         operationChecked = false;
         if (digitGroupingCheck == true)
         {
             string decimalPart = "";
             if (TxtDisplay.Text.Contains(".") == true)
             {
                 decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
             }
             int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
             string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
             if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
             {
                 changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
             }
             if (TxtDisplay.Text.Contains("."))
             {
                 changedDisplay += decimalPart;
             }
             if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
             {
                 changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
             }
             if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
             {
                 changedDisplay += "0";
             }
             TxtDisplay.Text = changedDisplay;
         }
         else
         {
             double number = double.Parse(TxtDisplay.Text);
             TxtDisplay.Text = number.ToString("G");
         }
         EnableDisableButtons(true);
         BtnEqual.IsEnabled = true;
         BtnC.IsEnabled     = true;
         BtnCE.IsEnabled    = true;
     }
     if (e.Key == Key.Escape)
     {
         NumericalButtons(true);
         BtnEqual.IsEnabled           = true;
         BtnPoint.IsEnabled           = true;
         BtnCE.IsEnabled              = true;
         BtnMemoryAdd.IsEnabled       = true;
         BtnMemorySubstract.IsEnabled = true;
         BtnMemoryStore.IsEnabled     = true;
         TxtDisplay.Text              = "0";
         operations.numberStack.Clear();
         operations.operationStack.Clear();
         operations.previousValue = 0;
         EnableDisableButtons(true);
         if (digitGroupingCheck == true)
         {
             string decimalPart = "";
             if (TxtDisplay.Text.Contains(".") == true)
             {
                 decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
             }
             int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
             string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
             if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
             {
                 changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
             }
             if (TxtDisplay.Text.Contains("."))
             {
                 changedDisplay += decimalPart;
             }
             if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
             {
                 changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
             }
             if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
             {
                 changedDisplay += "0";
             }
             TxtDisplay.Text = changedDisplay;
         }
         else
         {
             double number = double.Parse(TxtDisplay.Text);
             TxtDisplay.Text = number.ToString("G");
         }
     }
     if (e.Key == Key.Enter || e.Key == Key.Return)
     {
         if (operations.numberStack.Count != 0 && operations.operationStack.Count != 0)
         {
             BtnCE.IsEnabled    = false;
             operationChecked   = false;
             BtnEqual.IsEnabled = false;
             BtnPoint.IsEnabled = true;
             BtnC.IsEnabled     = true;
             string text = operations.EqualOperation(TxtDisplay.Text);
             TxtDisplay.Clear();
             TxtDisplay.Text = text;
             if (TxtDisplay.Text == "Cannot divide by zero!")
             {
                 EnableDisableButtons(false);
                 NumericalButtons(false);
                 BtnEqual.IsEnabled           = false;
                 BtnPoint.IsEnabled           = false;
                 BtnCE.IsEnabled              = false;
                 BtnMemoryAdd.IsEnabled       = false;
                 BtnMemorySubstract.IsEnabled = false;
                 BtnMemoryStore.IsEnabled     = false;
             }
             if (TxtDisplay.Text == "Invalid input!")
             {
                 EnableDisableButtons(false);
                 NumericalButtons(false);
                 BtnEqual.IsEnabled           = false;
                 BtnPoint.IsEnabled           = false;
                 BtnCE.IsEnabled              = false;
                 BtnMemoryAdd.IsEnabled       = false;
                 BtnMemorySubstract.IsEnabled = false;
                 BtnMemoryStore.IsEnabled     = false;
             }
             if (TxtDisplay.Text != "Invalid input!" && TxtDisplay.Text != "Cannot divide by zero!")
             {
                 if (digitGroupingCheck == true)
                 {
                     string decimalPart = "";
                     if (TxtDisplay.Text.Contains(".") == true)
                     {
                         decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
                     }
                     int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
                     string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
                     if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
                     {
                         changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
                     }
                     if (TxtDisplay.Text.Contains("."))
                     {
                         changedDisplay += decimalPart;
                     }
                     if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
                     {
                         changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
                     }
                     if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
                     {
                         changedDisplay += "0";
                     }
                     TxtDisplay.Text = changedDisplay;
                 }
                 else
                 {
                     double number = double.Parse(TxtDisplay.Text);
                     TxtDisplay.Text = number.ToString("G");
                 }
                 EnableDisableButtons(true);
                 BtnEqual.IsEnabled = true;
             }
         }
     }
     if (e.Key == Key.Decimal)
     {
         if (BtnPoint.IsEnabled == true)
         {
             TxtDisplay.Text    = TxtDisplay.Text + ".";
             BtnPoint.IsEnabled = false;
         }
     }
     typeOfOperation = GetOperation(e);
     if (typeOfOperation != null)
     {
         BtnCE.IsEnabled = false;
         BtnC.IsEnabled  = true;
         EnableDisableButtons(false);
         BtnEqual.IsEnabled = false;
         BtnPoint.IsEnabled = true;
         string text = operations.MakeOperation(TxtDisplay.Text, typeOfOperation);
         TxtDisplay.Clear();
         TxtDisplay.Text = text;
         if (TxtDisplay.Text == "Cannot divide by zero!")
         {
             EnableDisableButtons(false);
             NumericalButtons(false);
             BtnEqual.IsEnabled           = false;
             BtnPoint.IsEnabled           = false;
             BtnCE.IsEnabled              = false;
             BtnMemoryAdd.IsEnabled       = false;
             BtnMemorySubstract.IsEnabled = false;
             BtnMemoryStore.IsEnabled     = false;
         }
         operationChecked = true;
         if (digitGroupingCheck == true)
         {
             string decimalPart = "";
             if (TxtDisplay.Text.Contains(".") == true)
             {
                 decimalPart = TxtDisplay.Text.Substring(TxtDisplay.Text.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
             }
             int    numberOnDisplay = (int)(double.Parse(TxtDisplay.Text));
             string changedDisplay  = numberOnDisplay.ToString("N", CultureInfo.CurrentCulture);
             if (changedDisplay.Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00"))
             {
                 changedDisplay = changedDisplay.Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "00", "");
             }
             if (TxtDisplay.Text.Contains("."))
             {
                 changedDisplay += decimalPart;
             }
             if (TxtDisplay.Text.Contains(".") && changedDisplay[changedDisplay.Length - 1] == '0')
             {
                 changedDisplay = changedDisplay.Substring(0, changedDisplay.Length - 1);
             }
             if (TxtDisplay.Text.Contains(".") == true && (e.Key == Key.D0 || e.Key == Key.NumPad0))
             {
                 changedDisplay += "0";
             }
             TxtDisplay.Text = changedDisplay;
         }
         else
         {
             double number = double.Parse(TxtDisplay.Text);
             TxtDisplay.Text = number.ToString("G");
         }
     }
 }
Exemplo n.º 19
0
 private void BtnClear_Click(object sender, EventArgs e)
 {
     TxtDisplay.Clear();
 }