Enable Keyboard

0

I share my question, I have a numericUpDown and I want what to write a number, if this is greater than 10 digits block or disable writing. Below I leave an example of what I've been up to now, but that's where I "get".

Thank you in advance for your opinions.

private void nudNumSeguro_ValueChanged(object sender, EventArgs e)
{
     if(this.Text.Length == 10)
     {

     }
}
    
asked by Lorenzo Molina 14.03.2018 в 22:57
source

1 answer

1

You can check it in the event KeyPress : if the length is greater than or equal to 10 and it is not a control character (to allow deletion) the key is canceled:

private void numericUpDown1_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = ((NumericUpDown) sender).Text.Length >= 10
                && !char.IsControl(e.KeyChar);
}
    
answered by 15.03.2018 / 09:12
source