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;
        }

  

原文地址:https://www.cnblogs.com/wxbug/p/14852048.html