private void textBox1_TextChanged(object sender, System.EventArgs e)
{
string pat=@"[/u4e00-/u9fff]";
Regex rg=new Regex(pat);
Match mh=rg.Match(textBox1.Text);
if(!mh.Success)
return;
MessageBox.Show("不许输入中文");
textBox1.Undo();
}
{
string pat=@"[/u4e00-/u9fff]";
Regex rg=new Regex(pat);
Match mh=rg.Match(textBox1.Text);
if(!mh.Success)
return;
MessageBox.Show("不许输入中文");
textBox1.Undo();
}
本文介绍了一个简单的C#代码示例,用于实现在Windows窗体应用程序中禁止用户在TextBox控件内输入中文字符的功能。通过使用正则表达式匹配和Regex类,可以有效地阻止中文字符的输入,并在尝试输入时提示用户。
886

被折叠的 条评论
为什么被折叠?



