C# WinForm TextBox 只能输入数字【正则替换】
1 2 3 4 5 6 7 | private void txtMaxCount_TextChanged( object sender, EventArgs e) { //替换非数字 this .txtMaxCount.Text = Regex.Replace( this .txtMaxCount.Text, @"[^\d]*" , "" ); // 将光标定位到文本框的最后 this .txtMaxCount.SelectionStart = this .txtMaxCount.Text.Length; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步