使文本框内输入的文本长度在50内,且必须是英文字母!!要求要用代码实现,谢谢!
è¿æ¯éå¶å符ç.åªè½è¾å
¥å¤§å°å.è³äºè¾å
¥ææ¬çé¿åº¦.åªè¦æ¾å°ææ¬æ¡çmaxlengthçå±æ§å¼è®¾ç½®ä¸º50å³å¯.å¸æå å.å 为è¿éæ¯çµè常è¯,èä¸æ¯ç¼ç¨çåprivate void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//MessageBox.Show(e.KeyChar.ToString());
if(e.KeyChar>=65 & e.KeyChar<=90 || e.KeyChar >=97 & e.KeyChar<=122 )
{
e.Handled = false;
}
else
{
e.Handled = true;
} }
{
//MessageBox.Show(e.KeyChar.ToString());
if(e.KeyChar>=65 & e.KeyChar<=90 || e.KeyChar >=97 & e.KeyChar<=122 )
{
e.Handled = false;
}
else
{
e.Handled = true;
} }
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-07-12
把括号里的 System.Windows.Forms.去掉 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)