您的位置:首页 > 其它

e.Handled 的应用,控制textBox所输入内容

2013-03-25 13:19 120 查看
 

           Handled     获取或设置一个值,该值指示是否处理过   KeyPress   事件   ,  
           e.Handled   =   true;//为true时表示已经处理了事件(即不处理当前键盘事件)

           e.Handled为false的时候表示可以接受该事件

           KeyChar     获取或设置与按下的键对应的字符

1. 设置textBox只可输入数字,并识别退格键

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))//如果不是退格键和数字
{ e.Handled = true; }
}

2.设置textBox不识别空格键:

private void textBox25_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == ' ') e.Handled = true;
}

textBox输入两个数字后,自动跳转到下一个textBox表格并选中其所有内容

private void NUM_TextChanged(object sender, EventArgs e)
{
if (((TextBox)sender).SelectionLength > 0) return;
if (((TextBox)sender).Text.Length >= 2)
{
SelectNextControl((Control)sender, true, true, true, true);
((TextBox)ActiveControl).SelectAll();
}
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: