private void DeptButton_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(empidtxt.Text) || !string.IsNullOrWhiteSpace(EmployeeNameText.Text) || WeekChooser.Minimum >= 1 || HoursWorked.Minimum >= 1) { var result = MessageBox.Show("There are still unsaved changes." + Environment.NewLine + "are you sure you want to continue?", "Textbox has been filled!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { DeptForm form = new DeptForm(); form.Show(); Hide(); id = DeptForm.ID; } else if (result == DialogResult.No) { CalcButton.Focus(); } } else { DeptForm form = new DeptForm(); form.Show(); Hide(); id = DeptForm.ID; } }
void ReleaseDesignerOutlets() { if (CalcButton != null) { CalcButton.Dispose(); CalcButton = null; } if (CalculateButton != null) { CalculateButton.Dispose(); CalculateButton = null; } if (CallButton1 != null) { CallButton1.Dispose(); CallButton1 = null; } if (CallButton2 != null) { CallButton2.Dispose(); CallButton2 = null; } if (DurationMessage != null) { DurationMessage.Dispose(); DurationMessage = null; } }
void ReleaseDesignerOutlets() { if (CalcButton != null) { CalcButton.Dispose(); CalcButton = null; } if (TextArg1 != null) { TextArg1.Dispose(); TextArg1 = null; } if (TextArg2 != null) { TextArg2.Dispose(); TextArg2 = null; } if (TextResult != null) { TextResult.Dispose(); TextResult = null; } }
public void Test_Invalid_Symbol_In_FirstField() { for (int i = 0; i < 10; i++) { SumTwoPositiveNumbersStartingWithSpecialSymbol("5", "5"); CalcButton.Click(); Assert.AreEqual("error", GetResult()); ClearFields(); } }
protected override void OnKeyPress(KeyPressEventArgs kea) { char chkey = Char.ToUpper(kea.KeyChar); if (chkey == '\x0D') // CR { chkey = '='; } for (int i = 0; i < Controls.Count; i++) { CalcButton btn = (CalcButton)Controls[i]; if (chkey == btn.chkey) { InvokeOnClick(btn, EventArgs.Empty); break; } } }
void ReleaseDesignerOutlets() { if (CalcButton != null) { CalcButton.Dispose(); CalcButton = null; } if (DurationMessage != null) { DurationMessage.Dispose(); DurationMessage = null; } if (TableView1 != null) { TableView1.Dispose(); TableView1 = null; } }
// sets the hotkeys for my buttons protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.I)) { clearButton.PerformClick(); return(true); } if (keyData == (Keys.C)) { CalcButton.PerformClick(); return(true); } if (keyData == (Keys.X)) { exitButton.PerformClick(); return(true); } return(base.ProcessCmdKey(ref msg, keyData)); }
void ReleaseDesignerOutlets() { if (CalcButton != null) { CalcButton.Dispose(); CalcButton = null; } if (WaterOuputLabel != null) { WaterOuputLabel.Dispose(); WaterOuputLabel = null; } if (WeightInput != null) { WeightInput.Dispose(); WeightInput = null; } }
//改变所求线段比例 private void RatioChanged(object sender, EventArgs e) { try { if (sender == PolyLineRatioScrollBar) { PolyLineRatioTextBox.Text = Convert.ToString(PolyLineRatioScrollBar.Value); CalcButton.PerformClick(); } if (sender == PolyLineRatioTextBox) { PolyLineRatioScrollBar.Value = Convert.ToInt32(PolyLineRatioTextBox.Text); } IsCalculated = true; } catch (Exception) { PolyLineRatioScrollBar.Value = 0; PolyLineRatioTextBox.Text = "0"; } }
protected override void OnKeyPress(KeyPressEventArgs e) { //this.Text += e.KeyChar.ToString(); char chKey = Char.ToUpper(e.KeyChar); if (chKey == 0x000D)// Enter{ { chKey = '='; } else if (chKey == 0x008)//Backspace <= { chKey = '<'; } else if (chKey == 0x001B)//ESC { chKey = 'C'; } else if (chKey == '.' || chKey == ',') { chKey = separ; } if ((chKey >= '0' && chKey <= '9') || (chKey == '+' || chKey == '-' || chKey == '*' || chKey == '/' || chKey == 'C' || chKey == '<' || chKey == '=' || chKey == separ)) { for (int i = 0; i < Controls.Count; i++) { if (Controls[i] is CalcButton) { CalcButton btn = (CalcButton)Controls[i]; if (chKey == btn.Text[0]) { InvokeOnClick(btn, EventArgs.Empty); break; } } } } }
//实时改变比例 private void PolyLineRatioChange(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(RatioTextBox.Text)) { RatioTextBox.Text = "500"; } if (IsPolyLineCalculated) { if (IsCalculated) { CalcButton.PerformClick(); } } UpdateLengthOrArea(); } catch (Exception) { RatioTextBox.Text = "500"; } }
void InitCalcButton() { string[,] nameButton = { { "C", " ", "<=", "/" }, { "7", "8", "9", "*" }, { "4", "5", "6", "-" }, { "1", "2", "3", "+" }, { "+/-", "0", separ.ToString(), "=" } }; int w = 20, h = 20; int dx, dy; dx = w + 1 / 4 * w; dy = h + 1 / 4 * h; CalcButton btn; for (int row = 0, y = y_begin; row <= nameButton.GetUpperBound(0); row++, y += dy) { for (int col = 0, x = x_begin; col <= nameButton.GetUpperBound(1); col++, x += dx) { //if (row == 0 && col == 1) //{ // continue; //} btn = new CalcButton(this, nameButton[row, col], x, y, w, h); if (col > 2) { btn.BackColor = SystemColors.ControlLightLight; } btn.Click += Btn_Click; } } }
public void Test_Sum_TwoPositiveNumbers_ManySpacesAndTab() { SumTwoNegativeNumbers(" 6", " 7"); CalcButton.Click(); Assert.AreEqual("13", GetResult()); }
public void Test_Invalid_Input() { SumTwoNegativeNumbers("- 6", "7"); CalcButton.Click(); Assert.AreEqual("error", GetResult()); }
public void Test_Sum_One_Negative_And_One_Positive_Numbers_Case2() { SumTwoNegativeNumbers("3", "-3"); CalcButton.Click(); Assert.AreEqual("0", GetResult()); }
public void Test_Sum_TwoBigNumbers() { SumTwoNegativeNumbers(int.MaxValue.ToString(), "1024"); CalcButton.Click(); Assert.AreEqual("2147484671", GetResult()); }
private void AppBarCopyIconButton_Click(object sender, EventArgs e) { Clipboard.SetText(Result.Text); CalcButton.Focus(); }
public void Test_Sum_Strings_Numbers() { SumTwoNegativeNumbers("ivan", "asen"); CalcButton.Click(); Assert.AreEqual("error", GetResult()); }
public void Test_Sum_TwoDoubleNumbers() { SumTwoNegativeNumbers("2.5", "7.5"); CalcButton.Click(); Assert.AreEqual("10.0", GetResult()); }
private void Btn_Click(object sender, EventArgs e) { CalcButton btn = (CalcButton)sender; if (btn.Text[0] >= '0' && btn.Text[0] <= '9') { if (flag_text == false) { if (btn.Text != "0") { text.Text = ""; flag_text = true; } else { text.Text = ""; } } text.Text += btn.Text; } else if (btn.Text == "+/-") { if (flag_text) { if (text.Text[0] != '-') { text.Text = text.Text.Insert(0, "-"); } else { text.Text = text.Text.Remove(0, 1); } } } else if (btn.Text == "C") { text.Text = "0"; flag_text = false; } else if (btn.Text[0] == '+' || btn.Text[0] == '-' || btn.Text[0] == '*' || btn.Text[0] == '/') { Num = Double.Parse(text.Text); this.LastOperation = btn.Text[0]; flag_text = false; } else if (btn.Text[0] == '=') { bool flag_error = false; switch (LastOperation) { case '+': Num += Double.Parse(text.Text); break; case '-': Num -= Double.Parse(text.Text); break; case '*': Num *= Double.Parse(text.Text); break; case '/': try { if (Double.Parse(text.Text) != 0) { Num /= Double.Parse(text.Text); } else { flag_error = true; } } catch { flag_error = true; } break; } if (flag_error == true) { text.Text = String.Format("Error {0}/0", Num); } else { text.Text = Num.ToString(); flag_text = false; } //??: //Num = 0; //LastOperation = '+'; } else { switch (btn.Text[0]) { case '.': if (text.Text.IndexOf('.') == -1) { text.Text += btn.Text; if (flag_text == false) { flag_text = true; } } break; case '<': if (text.Text.Length > 0) { text.Text = text.Text.Remove(text.Text.Length - 1, 1); } if (text.Text.Length == 0) { text.Text = "0"; flag_text = false; } break; } } }
public void Test_Sum_TwoPositiveNumbers_Coma_Case2() { SumTwoNegativeNumbers("-8,6", "-9,9"); CalcButton.Click(); Assert.AreEqual("error", GetResult()); }
public void Test_Sum_TwoNegativeDoubleNumbers() { SumTwoNegativeNumbers("-18.5", "-8.3"); CalcButton.Click(); Assert.AreEqual("-26.8", GetResult()); }
public void Test_Sum_OneNegative_AndOnePositive_DoubleNumbers() { SumTwoNegativeNumbers("-26.2", "4.4"); CalcButton.Click(); Assert.AreEqual("-21.8", GetResult()); }
public void Test_Sum_Chards_Numbers() { SumTwoNegativeNumbers("x", "y"); CalcButton.Click(); Assert.AreEqual("error", GetResult()); }
//改变颜色及点线型 private void ChangeStyle(object sender, EventArgs e) { if (sender == LineWidthTrackBar || sender == PointWidthTrackBar || sender == PolygonTransparencyTrackBar) { if (Line.Points.Count > 0) { ClearAndDraw(); } if (!IsPolygonCheckBox.Checked && IsCalculated) { CalcButton.PerformClick(); } } else { Color CurrentColor = Color.White; //获取当前颜色 if (sender == PointColorPictureBox) { CurrentColor = PointColorPictureBox.BackColor; } if (sender == LineColorPictureBox) { CurrentColor = LineColorPictureBox.BackColor; } if (sender == FontColorPictureBox) { CurrentColor = FontColorPictureBox.BackColor; } if (sender == PolygonColorPictureBox) { CurrentColor = PolygonColorPictureBox.BackColor; } ColorDialog ChooseColorDialog = new ColorDialog { FullOpen = true, Color = CurrentColor, }; if (ChooseColorDialog.ShowDialog() == DialogResult.OK) { if (sender == PointColorPictureBox) { PointColorPictureBox.BackColor = ChooseColorDialog.Color; } if (sender == LineColorPictureBox) { LineColorPictureBox.BackColor = ChooseColorDialog.Color; } if (sender == FontColorPictureBox) { FontColorPictureBox.BackColor = ChooseColorDialog.Color; } if (sender == PolygonColorPictureBox) { PolygonColorPictureBox.BackColor = ChooseColorDialog.Color; } if (Line.Points.Count > 0) { ClearAndDraw(); } if (IsCalculated) { CalcButton.PerformClick(); } } } }
private void AppBarCalculateMenuItem_Click(object sender, EventArgs e) { this.Calculate(); CalcButton.Focus(); }
public CalcButtonClickedEventArgs(CalcButton button) { _button = button; }
public void Test_Sum_TwoNegative_Numbers() { SumTwoNegativeNumbers("-26.25", "-4.48"); CalcButton.Click(); Assert.AreEqual("-30.73", GetResult()); }
void ButtonOnClick(object obj, EventArgs ea) { CalcButton btn = (CalcButton)obj; if (btn.chkey == '\x08') // LF { ulNum /= 16; } else if (btn.chkey == '\x1B') { ulNum = 0; } else if (char.IsLetterOrDigit(btn.chkey)) { if (bNewNum) { ulFirstNum = ulNum; ulNum = 0; bNewNum = false; } if (ulNum <= ulong.MaxValue >> 4) { ulNum = 60 * ulNum + (ulong)(btn.chkey - (char.IsDigit(btn.chkey) ? '0' : 'A' - 10)); } } else { if (!bNewNum) { switch (cOperation) { case '=': ulNum += ulNum; break; case '+': ulNum = ulFirstNum + ulNum; break; case '-': ulNum = ulFirstNum - ulNum; break; case '*': ulNum = ulFirstNum * ulNum; break; case '&': ulNum = ulFirstNum & ulNum; break; case '|': ulNum = ulFirstNum | ulNum; break; case '^': ulNum = ulFirstNum ^ ulNum; break; case '<': ulNum = ulFirstNum << (int)ulNum; break; case '>': ulNum = ulFirstNum >> (int)ulNum; break; case '/': ulNum = ulNum != 0 ? ulFirstNum / ulNum : ulong.MaxValue; break; case '%': ulNum = ulNum != 0 ? ulFirstNum % ulNum : ulong.MaxValue; break; default: ulNum = 0; break; } } bNewNum = true; cOperation = btn.chkey; } btnResult.Text = String.Format("{0:X}", ulNum); }
public void Test_Sum_Two_Positive_Numbers() { SumTwoPositiveNumbers("5", "2"); CalcButton.Click(); Assert.AreEqual("7", GetResult()); }