![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private void txtName_KeyDown(object sender, KeyEventArgs e) { Regex rg = new Regex("^[u4e00-u9fa5]$"); //是退格键 if (!rg.IsMatch(e.Key.ToString())) { e.Handled = true; } if (txtName.Text.Length >= 20) { txtName.Text = txtName.Text.Substring(0, 20); EasySL.Controls.Window.Alert("请输入20内的名称", this.floatePanel); } }