本文介绍了关键新闻事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了按键事件的问题。当我在textbox1中输入10位数时,它需要10位数。但是当我清除textbox1按退格键然后再输入数字时,它只需9位数就是我的问题。请告诉我我的代码出现了什么问题,如

I have problem with keypress event. when i enter 10 digits in textbox1 it takes 10 digits as i want. but when i clear textbox1 pressing backspace and now enter digits again it takes only 9 digits that is my problem. please tell me what's going wrong with my code is given as under

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar != '\b' && textBox4.Text.Trim().Length > 9)
    {
        //here '\b' is for backspace
        e.Handled = true;
        MessageBox.Show("You can't enter more than ten digits...");
        textBox4.MaxLength = 9;
    }
}

推荐答案



这篇关于关键新闻事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:25