C#中如何限制comboBox中只能输入字母,其他的字符不能输入。
解决方案 »
- 屏幕分辨率改变后panel中控件显示问题
- 求大神 类型System.String的对象无法转换成类型System.Object[]。。
- GeckoWebWrowser控件的使用问题
- 怎么把数据库中的一列显示为datagridview的字段名?
- 救命啊,大侠救命,针对"{74946829-37A0-11D2-A273-00C04F8EF4FF}" 的QueryService失败...是什么问题呐.我搞晕了...
- 多表问题?
- Process.Length-1 什么意思。
- 新手求助,通过list泛型用List存List
- 用Apache可不可以运行C#(web form)
- [求助]c#winform绘图在Paint错位
- C#时间问题,知道的大人进
- 弹出新窗口不刷新原来页面
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
if (e.KeyChar == (char)8)
e.Handled = false;
}
{
string pattern = @"^[A-Za-z]*$";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern);
if (!reg.IsMatch(this.comboBox1.Text))
{
e.Cancel = true;
}
}输入不正确焦点则不能离开comboBox控件,或者在comboBox1_TextChanged事件中进行判断也可
{
e.Handled = false;
}
else
{
if((e.KeyChar !=8)&&(e.KeyChar !=13))
{
e.Handled = true;
}
}
自己刚才整了个似乎好用
Match m = Regex.Match(comboBox1.Text, regular);
if (m.Success)
{
...
}
else
{
...
}