手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

C#winform怎样禁止非法字符的输入

时间:2024-10-11 19:06:10

1、打开visual studio2010,添加“解决方案”--“新建项目”

C#winform怎样禁止非法字符的输入

2、窗体布局如下:三个Lable控件,三个TextBoxe控件,两个Button控件

C#winform怎样禁止非法字符的输入

3、关键步骤:1、选中用户名输入的TextBoxe控件,2、选择属性--事件--选择KeyPress事件,双击

C#winform怎样禁止非法字符的输入

4、在弹出的代码编辑窗,输入下列代码:namespace 经验{ public pa筠续师诈rtial class Form1 : Form 撑俯擂摔{ public Form1() { InitializeComponent(); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {//此为只能输入字母 if (e.KeyChar < 'A' || e.KeyChar > 'Z' && e.KeyChar < 'a' || e.KeyChar > 'z') { e.Handled = true; }//此为退格键可以输入 if (e.KeyChar == 8) { e.Handled = false; } } }}

C#winform怎样禁止非法字符的输入

5、ok!在用户名栏里,只能输入字母了。

C#winform怎样禁止非法字符的输入
© 手抄报圈