// ********************************** Capture button's click event *********************************** void MyButtonClick(object sender, EventArgs e) { try { Button button = sender as Button; string szTemp = ""; if (!liszSymbols.Contains(button.Content) && button.Content.ToString() != "Enter" && boClearList) { CurrentText.Text = ""; boClearList = false; } if (button.Content.ToString() == "C") { ClearLists(); CurrentText.Text = ""; } else if (button.Content.ToString() == "<") { if (CurrentText.Text.Length != 0) { CurrentText.Text = CurrentText.Text.Remove(CurrentText.Text.Length - 1, 1); } } else if (button.Content.ToString() != "Enter") { if (!liszSymbols.Contains(button.Content)) { if (button.Content.ToString() == "." && !CurrentText.Text.Contains(".")) { CurrentText.Text += button.Content.ToString(); } else if (button.Content.ToString() != ".") { CurrentText.Text += button.Content.ToString(); } } else { lidoValues.Add(double.Parse(CurrentText.Text)); liszOperations.Add(button.Content.ToString()); HistoryText.Text += CurrentText.Text + button.Content.ToString(); CurrentText.Text = ""; } } else if (button.Content.ToString() == "Enter") { if (!string.IsNullOrEmpty(CurrentText.Text)) { lidoValues.Add(double.Parse(CurrentText.Text)); if (button.Content.ToString() != "C") { HistoryText.Text += CurrentText.Text; szTemp = HistoryText.Text; } double doResutl = 0; for (int i = 0; i < liszOperations.Count; i++) { doResutl = DoOperation(lidoValues[i], lidoValues[i + 1], liszOperations[i]); lidoValues[i + 1] = doResutl; } if (doResutl != 0) { CurrentText.Text = doResutl.ToString("N4"); } else { CurrentText.Text = "0"; } ClearLists(); boClearList = true; liszOperationsHistory.Insert(0, $"{szTemp} = {CurrentText.Text}"); } } CurrentText.Focus(); } catch { AlertBar("Invalid input", 2); } }