第1个回答 2008-04-02
this.richTextBox1.KeyPress += new KeyPressEventHandler(richTextBox1_KeyPress);
//上面的你在构造函数里订阅这个事件
void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string str = @"[a-zA-Z0-9]";
e.Handled = !System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), str);
}
//这样就可以了~用了正则表达式