How can I accept the backspace key in the keypress event?

后端 未结 8 582
长情又很酷
长情又很酷 2020-12-16 10:39

This is my code:

private void txtAdd_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!(char.IsLetter(e.KeyChar)) && !(char.IsNumber(e.KeyChar)         


        
8条回答
  •  萌比男神i
    2020-12-16 11:27

    You have to add !(char.IsControl(e.KeyChar)) in you sentence and that's it.

    private void txtNombre_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!(char.IsLetter(e.KeyChar)) && !(char.IsNumber(e.KeyChar)) && !(char.IsControl(e.KeyChar)) && !(char.IsWhiteSpace(e.KeyChar)))
                {
                    e.Handled = true;
                }
            }
    

提交回复
热议问题