e.KeyCode == Keys.Space KeyDown 事件中加上这个
用代码限制 ASC码=空格的ASC码时候 不做操作
enable 设置成 false
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
return;
}
}
private void txt_CategoryName_KeyPress(object sender, KeyPressEventArgs e)
{
//此为只能输入字母A到Z和a到z
if (e.KeyChar < 'A' || e.KeyChar > 'Z' && e.KeyChar < 'a' || e.KeyChar > 'z')
{
e.Handled = true;
}
//此为可以输入数字
if (e.KeyChar > 0 || e.KeyChar < 9)
{
e.Handled = false;
}
//此为退格键可以输入
if (e.KeyChar == 8)
{
e.Handled = false;
}
//此为禁止空格键输入
if (e.KeyChar == ' ')
e.Handled = true;
}