C# WinForm TextBox 只能输入数字【正则替换】
private void txtMaxCount_TextChanged(object sender, EventArgs e) { //替换非数字 this.txtMaxCount.Text = Regex.Replace(this.txtMaxCount.Text, @"[^\d]*", ""); // 将光标定位到文本框的最后 this.txtMaxCount.SelectionStart = this.txtMaxCount.Text.Length; }