Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In C#, how does TextBox only let users input plastic? And how to let users only input more than 5 digits?
In C#, how does TextBox only let users input plastic? And how to let users only input more than 5 digits?
Hello:

Why does TextBox only let users input shapes?

Overwrite keyboard events on KeyPress ()

By overriding the OnKeyPress () event of the TextBox control, you can handle the characters entered by the keyboard, as shown in the following code:

//Block non-numeric keys

Protected coverage void on keypress (keypress eventargse) {

Base. Key (e);

//Read only, do not process

If (this. Read only)

{Return; }

//Special keys (including spaces) will not be processed.

if((int)e . key char & lt; = 32)

{Return; }

//Non-numeric keys, give up input.

If (! Charles. IsDigit(e.KeyChar))

{e. Handled = true returns; }

}

How to let users only input more than 5 digits?

It should be enough to set the minlength property of textbox, or take the input string to judge whether the length is less than 5, and then you will be prompted.