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

 

           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(); 
            }
        }



 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值