how to block the space key in a text field c #

0

How can I block the space key when writing over a text field to prevent the user from entering a space when registering something? I currently control only letters and numbers in the Keypress. I need no field to be sent to the database with spaces.

 //letras y numeros
if (Char.IsLetter(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsDigit(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
    
asked by sebastian bizama inostroza 22.11.2017 в 21:31
source

1 answer

0

Your validation for separator has the e.handled to the revez, it should be:

 if (char.IsSeparator(e.KeyChar))
        {
            e.Handled = true;
        }

        else
        {
            e.Handled = false;
        }

by the way, you have to search for the OnKeyPress event

    
answered by 24.11.2017 в 21:35