MaxLenght bug.


I tried to use the MaxLength property of the control and it does not work out of the box as supposed to be. In fact the lack of it leaves open for an overflow exception when exceeding the value of the decimal value of the currency control.

I modified the control with a minor patch on the TextBox_PreviewKeyDown event and it seems to work now.

I'll leave the patch here so anyone can implement or better if the creator of the control can update to fix this bug.
e.Handled = true;

if ((sender as TextBox).MaxLength!=0 && (sender as TextBox).MaxLength <= (sender as TextBox).Text.Length)
                } //patch
                else if (Number < 0) //Push the new number from the right
                    Number = (Number * 10M) - (GetDigitFromKey(e.Key) / 100M);


abbaye wrote Jan 24, 2016 at 7:49 PM

Thank for issues i have implemented in my version on this control.

another alternative :)
            if (tb.MaxLength != 0 && Number.ToString().Length > tb.MaxLength)