C# WinForm TextBox 只能输入数字【正则替换】
时间:2021-06-05 18:15:46
收藏:0
阅读:0
private void txtMaxCount_TextChanged(object sender, EventArgs e) { //替换非数字 this.txtMaxCount.Text = Regex.Replace(this.txtMaxCount.Text, @"[^\d]*", ""); // 将光标定位到文本框的最后 this.txtMaxCount.SelectionStart = this.txtMaxCount.Text.Length; }
评论(0)