private void txtSearchText_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (int)Keys.Enter) { FindInst(); } }
//===================================================================== /// <summary> /// Only allow digits to be entered and backspace to be pressed. /// </summary> /// <param name="e">The event arguments</param> protected override void OnKeyPress(KeyPressEventArgs e) { if((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == '\b') base.OnKeyPress(e); else e.Handled = true; }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ("1234567890".IndexOf(e.KeyChar) == -1 && e.KeyChar != '\b') { e.Handled = true; } }
void tbxServerPort_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } }
private void DataList1_DblClick(System.Object eventSender, KeyPressEventArgs eventArgs) { // ERROR: Not supported in C#: OnErrorStatement if (string.IsNullOrEmpty(DataList1.BoundText)) return; int lID = 0; lID = Convert.ToInt32(DataList1.BoundText); switch (gSection) { case -1: gID = Convert.ToInt32(DataList1.BoundText); this.Close(); break; case 0: My.MyProject.Forms.frmStockItem.loadItem(ref Convert.ToInt32(DataList1.BoundText)); frmStockItem formItem = null; formItem.Show(); break; case 1: My.MyProject.Forms.frmStockPricing.loadItem(ref Convert.ToInt32(DataList1.BoundText)); frmStockPricing formPrice = null; formPrice.Show(); break; case 2: modApplication.report_StockQuantity(ref Convert.ToInt32(DataList1.BoundText)); break; } gRS.Requery(); //UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"' DataList1.CtlRefresh(); }
private void txtNum1_KeyPress(object sender, KeyPressEventArgs e) { if ((txtNum1.Text.Trim() + e.KeyChar.ToString()).Split('.').Length > 2) e.Handled = true; else if (!char.IsNumber(e.KeyChar) && (Keys)e.KeyChar != Keys.Back && e.KeyChar != '.') e.Handled = true; }
// este evento resolve a maioria dos problemas com a introdução // de valores inválidos nas datas, no entanto, ficam por tratar // outros modos de introdução dos dados (por exemplo fazendo "paste"). // embora geralmente não seja um problema pode se-lo nos casos em // que se torne necessário forçar um endedit. public void data_KeyPress(object sender, KeyPressEventArgs e) { if (! (char.IsDigit(e.KeyChar)) && ! (e.KeyChar == '?') && ! (char.IsControl(e.KeyChar))) { e.Handled = true; } }
void Settings_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)27) { this.Close(); } }
private void Contrasena_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { this.IngresarButton_Click(null, null); } }
private void ChangingPasswordInterface_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { SavePasswordAndLogin(); } }
private void txt_rut_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Convert.ToChar(Keys.Enter)) { RutVerificar(); } }
private void tbConfirmPw_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { btnChangePw_Click(sender, e); } }
private void textbox1_KeyPress(object sender, KeyPressEventArgs e) { // e.Handled MSDN 說明: // 若只是在表單層級處理鍵盤事件,而且不讓其他的控制項接收鍵盤事件, // 請將表單的 KeyPress 事件處理方法中的 KeyPressEventArgs.Handled 屬性設為 true。 e.Handled = !char.IsDigit(e.KeyChar); //&& !char.IsControl(e.KeyChar); }
private void playerTwo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar.ToString() == "\r") { playButton.PerformClick(); } }
private void PlaerNameTextBox_KeyPress(object sender, KeyPressEventArgs e) { if ((!Char.IsLetter(e.KeyChar)) && (e.KeyChar != 8)) { e.Handled = true; } }
private void QuantityText_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Convert.ToChar(Keys.Enter)){ dataGridView1.DataSource = tipo_pago_data.BuscarTipoPago(comboBox1.Text, textBox1.Text); textBox1.SelectAll(); } }
private void PriceText_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) { e.Handled = true; } }
private void ListatextBox_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= 48 && e.KeyChar <= 57) || (e.KeyChar >= 97 && e.KeyChar <= 122) || (e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar == 8)) e.Handled = false; else e.Handled = true; }
private void customerIDBox_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar) && !(e.KeyChar == (char)Keys.Back) && !(e.KeyChar == (char)Keys.Delete)) { e.Handled = true; } }
private void FormOverService_KeyPress(object sender, KeyPressEventArgs e) { if(e.KeyChar == 13)//enter this.button1.PerformClick(); else if(e.KeyChar == 27)//esc this.button2.PerformClick(); }
protected override void OnKeyPress(KeyPressEventArgs e) { Keys keyPressed = (Keys)e.KeyChar; if (_keys.Contains(keyPressed)) { e.Handled = false; } else { bool handleAlphabets = true; bool handleNumberic = true; int ascii = (int)e.KeyChar; if (_specialChars != null && (_specialChars.Contains(e.KeyChar))) e.Handled = false; else { handleAlphabets = (ascii >= 65 && ascii <= 90 || ascii >= 97 && ascii <= 122 || ascii == 32); handleNumberic = ascii >= 48 && ascii <= 57; e.Handled = (handleNumberic && _allowNumeric) || (handleAlphabets && _allowAlphabets); e.Handled = !e.Handled; } } if (e.Handled && BeepOnError) new SoundPlayer().Play(); base.OnKeyPress(e); }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == 8 || e.KeyChar == 13)) { e.Handled = true; } }
private void ChatInput_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (ChatInput.Text == "") return; if (IsPrivate && ChatInput.Text.StartsWith("/me")) { WriteMessage(new ChatMessage(MessageType.Message, CommandType.Me, Program.UserInfo, Name,Program.UserInfo.username + " " + ChatInput.Text.Replace("/me","").Trim())); Program.ChatServer.SendMessage(MessageType.PrivateMessage, CommandType.Me, Name, ChatInput.Text.Substring(4)); } else if (IsPrivate && ChatInput.Text.StartsWith("/")) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, Name, "Unknown Command.")); ChatInput.Clear(); e.Handled = true; return; } else if (IsPrivate) { WriteMessage(new ChatMessage(MessageType.PrivateMessage, CommandType.None, Program.UserInfo, Name, ChatInput.Text)); Program.ChatServer.SendMessage(MessageType.PrivateMessage, CommandType.None, Name, ChatInput.Text); } ChatInput.Clear(); e.Handled = true; } }
private void listBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { this.Close(); } }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { this.button1_Click(sender, e); } }
private void PowerForm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)0x1B) { CloseAndApply(); } }
private void txtAdres_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { webBrowser1.Navigate(txtAdres.Text); } }
private void AddCompanyForm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { bAdd.PerformClick(); } }
private void tbUpCol_KeyPress(object sender, KeyPressEventArgs e) { if (!Char.IsDigit(e.KeyChar) && !(e.KeyChar.ToString() == "," && tbBottomCol.Text.IndexOf(',') == -1) && (e.KeyChar != (char)Keys.Back)) { e.Handled = true; //Разрешение на ввод только цифр, одной запятой, одного знака минус } }
private void txtSearchDoc_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { try { blnTxtSearch = true; Reload_Documents(); } catch (Exception ex) { UDFLib.WriteExceptionLog(ex); } }
/// <summary> /// Key press event handler. /// This widget does nothing with key presses. /// </summary> /// <param name="e"></param> /// <returns></returns> public bool OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { return(false); }
internal void m_dgValores_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { OnCallDataGridKeyPressEvent(sender, e); }
//!!!this is never called (arrrgggghhh) private void SliceTreeNode_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Debug.WriteLine("TreeNode key press"); }
private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { MessageBox.Show("testing"); }
public static void AllowAllKey(object sender, System.Windows.Forms.KeyPressEventArgs e) { e.Handled = false; }
/// <summary> /// Die Event Methode die aufgerufen wird, wenn das Control eine KeyPress /// Notification erhält. /// </summary> /// <param name="e"> /// Die Argumente für den Keypress Event. /// </param> protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { base.OnKeyPress(e); inputProcessor.OnKeyPress(e); }
private void txtCount_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar != 13) { if (e.KeyChar == 8) { return; } if (e.KeyChar < 48 || e.KeyChar > 57) { e.Handled = true; return; } } else { int dCount = 0; int LastIg = int.Parse(this.txtIgCur.Text.Trim()); if (txtCount.Text.Trim() == "") { MessageBox.Show("数量不能为空!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } else { dCount = int.Parse(txtCount.Text.Trim()); } int dIgPay = 0; if (txtIgPay.Text.Trim() == "") { MessageBox.Show("需要的积分不能为空!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } else { dIgPay = int.Parse(txtIgPay.Text.Trim()); } if (txtGoodsID.Text.Trim() == "") { MessageBox.Show("商品信息有误,请重新选择商品!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); txtGoodsID.Text = ""; cmbGoodsName.Items.Clear(); cmbGoodsName.Refresh(); txtIgPay.Text = ""; txtCount.Text = ""; } if ((int.Parse(txtTolCharge.Text.Trim()) + dIgPay) > LastIg) { MessageBox.Show("所剩积分不能再兑换此商品!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } CMSMData.CMSMStruct.GoodsStruct gs = new CMSMData.CMSMStruct.GoodsStruct(); err = null; gs = cs.GetGoodsByID(txtGoodsID.Text.Trim(), out err); if (gs != null) { txtGoodsID.Text = gs.strGoodsID; cmbGoodsName.Text = gs.strGoodsName; bool sumflag = false; for (int i = 0; i < dtIgItem.Rows.Count; i++) { if (gs.strGoodsID == dtIgItem.Rows[i]["GoodsID"].ToString()) { dtIgItem.Rows[i]["Count"] = (int.Parse(dtIgItem.Rows[i]["Count"].ToString()) + dCount).ToString(); dtIgItem.Rows[i]["IgPay"] = (int.Parse(dtIgItem.Rows[i]["IgPay"].ToString()) + (dIgPay * dCount)).ToString(); sumflag = true; break; } } if (!sumflag) { DataRow dr = dtIgItem.NewRow(); dr[0] = gs.strGoodsID; dr[1] = gs.strGoodsName; dr[2] = dIgPay.ToString(); dr[3] = dCount.ToString(); dr[4] = (dIgPay * dCount).ToString(); dtIgItem.Rows.Add(dr); } this.DgBind(); txtCount.Focus(); } else { if (err != null) { clog.WriteLine(err); } MessageBox.Show("无此商品信息!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } }
private void txtCaption_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { char c = e.KeyChar; e.Handled = !(Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c) || Char.IsControl(c)); }
public virtual void DoKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { }
protected void AllowNumericOnly(System.Windows.Forms.KeyPressEventArgs e) { if (Char.IsDigit(e.KeyChar)) { if (this.SelectionStart == 0) { e.Handled = true; } else { if (this.intDollarCurLen == this.intDollarMaxLen && this.SelectionStart <= this.Text.IndexOf(".", 0)) { e.Handled = true; } else { if (this.intCentCurLen == this.intCentMaxLen && this.SelectionStart > this.Text.IndexOf(".", 0)) { e.Handled = true; } else { this.strLastKey = Convert.ToString(e.KeyChar); try { if (ReferenceCoreScenarioForm != null) { ReferenceCoreScenarioForm.m_bSave = true; } } catch { } // Digits are OK } } } } else if (e.KeyChar == '\b') { if (this.SelectionStart == 0) { e.Handled = true; } else { if (this.Text.Substring(this.SelectionStart - 1, 1) != "." && this.Text.Substring(this.SelectionStart - 1, 1) != "$") { try { ReferenceCoreScenarioForm.m_bSave = true; } catch { } //back space is okay if (ReferenceCoreScenarioForm != null) { ReferenceCoreScenarioForm.m_bSave = true; } this.strLastKey = "b"; } else { if (this.Text.Substring(this.SelectionStart - 1, 1) == ".") { this.SelectionStart = this.SelectionStart - 1; } e.Handled = true; } } } else { e.Handled = true; } }
public override void KeyPress(System.Windows.Forms.KeyPressEventArgs args) { }
private void glControl1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {//Keyboard control base.OnKeyPress(e); if (e.KeyChar == 27) { //Escape this.Close(); } switch (e.KeyChar.ToString().ToLower()[0]) { case 'w': //Forward Main.cam.Move(0f, 0.1f, 0f); Draw.UpdateImage(Width, Height); PosData(); break; case 'a': //Left Main.cam.Move(-0.1f, 0f, 0f); Draw.UpdateImage(Width, Height); PosData(); break; case 's': //Backward Main.cam.Move(0f, -0.1f, 0f); Draw.UpdateImage(Width, Height); PosData(); break; case 'd': //Right Main.cam.Move(0.1f, 0f, 0f); Draw.UpdateImage(Width, Height); PosData(); break; case 'e': //Up Main.cam.Move(0f, 0f, 0.1f); Draw.UpdateImage(Width, Height); PosData(); break; case 'q': //Down Main.cam.Move(0f, 0f, -0.1f); Draw.UpdateImage(Width, Height); PosData(); break; case 'u': //Zoom In if (zo) { Main.cam.Zoom -= 40; Main.cam.Speed /= 3; Main.cam.Sensitivity /= 3; zo = false; } Draw.UpdateImage(Width, Height); break; case 'i': //Zoom Out if (!zo) { Main.cam.Zoom += 40; Main.cam.Speed *= 3; Main.cam.Sensitivity *= 3; zo = true; } Draw.UpdateImage(Width, Height); break; case 'j': //Previous Iteration LastIt(); break; case 'k': //Next Iteration NextIt(); break; case 'm': //Mini Map if (Main.MiniMap) { Main.MiniMap = false; Main.Map = Main.FEmpty.hollow().toDisplay(); } else { Main.MiniMap = true; } break; } }
private void txtMKhau_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { txtMKhau_R.Text = ""; txtMKhau_R.Visible = true; lbMKhau_R.Visible = true; }
private void txtNote_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { SetEditStatus(true); }
private void ViewerKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { core_.KeyPress(e.KeyChar); }
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { this.strLastKey = ""; this.bEdit = true; this.AllowNumericOnly(e); }
private void PassWordForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { }
private void txtDenominationCount_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { Methods clsMethods = new Methods(); e.Handled = clsMethods.AllNum(Convert.ToInt32(e.KeyChar)); }
private void plot_enter(object sender, System.Windows.Forms.KeyPressEventArgs e) { }
public void HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e) { this.onKeyPress(e.KeyChar); }
void controlToHook_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs windowsKeyPressEvent) { MatterHackers.Agg.UI.KeyPressEventArgs aggKeyPressEvent = new MatterHackers.Agg.UI.KeyPressEventArgs(windowsKeyPressEvent.KeyChar); widgetToSendTo.OnKeyPress(aggKeyPressEvent); windowsKeyPressEvent.Handled = aggKeyPressEvent.Handled; }
/// <summary> /// key has been pressed /// </summary> /// <param name="e"></param> protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { Char chrKeyPressed; Int32 intSelStart; Int32 intDelTo; String strText; bool bolDelete; Int32 i; bool HadEnough; HadEnough = false; if ((this.ControlMode == TMaskedTextBoxMode.NormalTextBox) || (this.ControlMode == TMaskedTextBoxMode.Extract)) { // just be a textbox! e.Handled = false; return; } if (this.ReadOnly == true) { // no further action e.Handled = true; return; } chrKeyPressed = e.KeyChar; // Original cursor position intSelStart = this.SelectionStart; if (this.SelectionLength == this.Text.Length) { if (!(Control.ModifierKeys == Keys.Control)) { ClearBox(); intSelStart = this.Text.Length; } } if ((intSelStart == this.Text.Length) && (this.ControlMode == TMaskedTextBoxMode.PartnerKey)) { // insert from right in partner key mode if ((chrKeyPressed != (char)(CONTROL_CHARS_BACKSPACE)) && (System.Char.IsDigit(chrKeyPressed) == true)) { strText = this.Text.Remove(0, 1); strText = strText + this.PlaceHolder; this.Text = strText; intSelStart = intSelStart - 1; this.SelectionStart = intSelStart; } } // In case of a selection, delete text to this position intDelTo = this.SelectionStart + this.SelectionLength - 1; strText = this.Text; // Used to avoid deletion of the selection when an invalid key is pressed bolDelete = false; e.Handled = true; if (chrKeyPressed == (char)(CONTROL_CHARS_BACKSPACE)) { bolDelete = true; if ((intSelStart > 0) && (intDelTo < intSelStart)) { intSelStart = intSelStart - 1; } } // Find the Next Insertion point for (i = this.SelectionStart; i <= this.Mask.Length - 1; i += 1) { if (HadEnough == false) { // Test for # or & if ((this.Mask[i] == '#') && (System.Char.IsDigit(chrKeyPressed) == true)) { strText = strText.Remove(i, 1).Insert(i, new String(chrKeyPressed, 1)); intSelStart = i + 1; bolDelete = true; } if ((this.Mask[i] == '&') && (System.Char.IsLetter(chrKeyPressed) == true)) { strText = strText.Remove(i, 1).Insert(i, new String(chrKeyPressed, 1)); intSelStart = i + 1; bolDelete = true; } if ((this.Mask[i] == '!') && (System.Char.IsLetterOrDigit(chrKeyPressed) == true)) { strText = strText.Remove(i, 1).Insert(i, new String(chrKeyPressed, 1)); intSelStart = i + 1; bolDelete = true; } } // end of HadEnought test // Prevent looping unitl the next available match when mixing # & ! on the same mask if (System.Array.IndexOf(FParams, this.Mask[i]) > -1) { HadEnough = true; } } // end of loop if (bolDelete == true) { for (i = intSelStart; i <= intDelTo; i += 1) { if (System.Array.IndexOf(FParams, this.Mask[i]) > -1) { strText = strText.Remove(i, 1).Insert(i, this.PlaceHolder); } } this.Text = strText; this.SelectionStart = intSelStart; this.SelectionLength = 0; } }
private void textBoxTerminalNo_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { e.Handled = true; }
private void txtPackageDesc_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { m_bSave = true; }
private void txtFloatingBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { OnKeyPress(e); }
private void _editControl_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { //MAYBE Optionally PasswordChar *** during editing for protected strings switch (e.KeyChar) { case (char)(int)Keys.Escape: { // TODO if addentry remove it // Close and cancel EndEditing(false); break; } case (char)(int)Keys.Enter: { // Close and save EndEditing(true); break; } case (char)(int)Keys.Right: { EndEditing(true, true); ListViewItem Item = _editItem; int SubItem = GetNextSubItemFor(_editSubItem); StartEditing(Item, SubItem, true); break; } case (char)(int)Keys.Left: { EndEditing(true, true); ListViewItem Item = _editItem; int SubItem = GetPreviousSubItemFor(_editSubItem); StartEditing(Item, SubItem, true); break; } case (char)(int)Keys.Up: { EndEditing(true, true); ListViewItem Item = GetPreviousItemFor(_editItem); int SubItem = _editSubItem; StartEditing(Item, SubItem, true); break; } case (char)(int)Keys.Down: { EndEditing(true, true); ListViewItem Item = GetNextItemFor(_editItem); int SubItem = _editSubItem; StartEditing(Item, SubItem, true); break; } case (char)(int)Keys.Tab: { //TODO add new function NextEditing //NextEditing(_editItem, SubItem); // Save and edit next SubItem ListViewItem Item = _editItem; int SubItem = 0; EndEditing(true, true); if (Control.ModifierKeys == Keys.Shift) { SubItem = GetPreviousSubItemFor(_editSubItem); } else { SubItem = GetNextSubItemFor(_editSubItem); } StartEditing(Item, SubItem, true); break; } } }
private void txtSendData_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { e.Handled = KeyHandled; }
private void HotKeys(object sender, System.Windows.Forms.KeyPressEventArgs e) { }
private void TextBoxNumeric_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { int index; string text; if ((Char.IsControl(e.KeyChar) == true)) { if (e.KeyChar != 8) { e.Handled = true; return; } else if (ISBackallowed) { e.Handled = true; } return; } string pattern = "^[" + Regex.Escape(NumberFormatInfo.CurrentInfo.PositiveSign + NumberFormatInfo.CurrentInfo.NegativeSign) + "]?"; switch (Mask) { case TextBoxType.Decimal: // Match 0 or more digits, optionally follow by a decimal seprator, then optionally more digits. pattern += @"\d*[" + Regex.Escape(NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator) + Regex.Escape(NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) + @"]?\d"; if (Precision > 0) { pattern += "{0," + Precision.ToString(CultureInfo.InvariantCulture) + "}$"; } else { pattern += "*$"; } break; default: // Integer pattern += @"\d*$"; // Match 0 or more digits. break; } index = this.SelectionStart - this.GetFirstCharIndexFromLine(this.GetLineFromCharIndex(this.SelectionStart)); System.Globalization.NumberFormatInfo numberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat; string decimalSeparator = numberFormatInfo.NumberDecimalSeparator; string groupSeparator = numberFormatInfo.NumberGroupSeparator; // string text = this.Text.Insert(index, e.KeyChar.ToString()); text = this.Text ?? string.Empty; if (this.SelectionLength > 0) { text = text.Substring(0, this.SelectionStart) + text.Substring(this.SelectionStart + this.SelectionLength); index = this.SelectionStart; e.Handled = false; } text = text.Insert(index, e.KeyChar.ToString()); //this.Text = text; if (!Regex.IsMatch(text, pattern, RegexOptions.IgnoreCase)) { // Not a valid match, don't add the text. e.Handled = true; } else if (!ValidateLength(Mask, text, Precision)) { e.Handled = true; } }