字符串输入控制

//只能输入大写
private
void textBox1_KeyPress(object sender, KeyPressEventArgs e) { e.KeyChar = e.KeyChar.ToString().ToUpper().ToCharArray()[0]; }
// 只能输入数字,调用TextBox的KeyPress事件
private void txtUserId_KeyPress(object sender, KeyPressEventArgs e)
{
            //如果输入的不是数字键,也不是回车键、Backspace键,则取消该输入
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar!=(char)13 && e.KeyChar!=(char)8)
            {
                e.Handled = true;
            } 
} 
原文地址:https://www.cnblogs.com/quke123/p/4118512.html