本文原址:http://blog.sina.com.cn/s/blog_bde1f86f0102vj5b.html private void textBoxSize_KeyPress(object sender, KeyPressEventArgs e) { // Remove all characters that are not numbers, backspace, or enter. if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13) { e.Handled = true; } else if (e.KeyChar == 13) { // Apply size if the user hits enter TextBox txt = (TextBox)sender; if (txt.Text.Length > 0) ApplyTextSize(txt.Text); e.Handled = true; this.richTextBoxText.Focus(); } } 总结:Handled 获取或设置一个值,该值指示是否处理过KeyPress 事件 e.Handled = false的时候表示可以接受该事件 e.Handled = true时表示已经处理了事件(即不处理当前键盘事件) KeyChar 获取或设置与按下的键对应的字符