private void OnPreviewKeyDown(object sender, KeyEventArgs e) { TextBox textbox = sender as TextBox; int oldvalue = textbox.Text == string.Empty ? 0 : int.Parse(textbox.Text); if (oldvalue == 0 && (e.Key == Key.D0 || e.Key == Key.NumPad0)) { e.Handled = true; } if (KeyInputHelper.CanInputAssert(e.Key)) { if (KeyInputHelper.NumAssert(e.Key)) { int newvalue = 10 * oldvalue + KeyInputHelper.GetKeyValue(e.Key); if (!AssertOneSideRange(textbox, newvalue)) { e.Handled = true; } else if (textbox == MTextbox2 || textbox == DTextbox2 || textbox == STextbox2 || textbox == CVTextbox2) { if (!AssertWholeRange(textbox, newvalue, int.Parse(GetRefTextBox(textbox).Text))) { e.Handled = true; } } } } else { e.Handled = true; } }
private void OnPreviewKeyDown(object sender, KeyEventArgs e) { int oldvalue; if ((sender as TextBox).Text != string.Empty) { oldvalue = int.Parse((sender as TextBox).Text); } else { oldvalue = 0; } if (KeyInputHelper.CanInputAssert(e.Key)) { if (KeyInputHelper.NumAssert(e.Key)) { int newvalue = 10 * oldvalue + KeyInputHelper.GetKeyValue(e.Key); if (!AssertWholeRange((sender as TextBox), newvalue)) { e.Handled = true; } } } else { e.Handled = true; } }