Search code examples
c#.netwinforms.net-3.5maskedtextbox

MaskedTextBox Minimum/Maximum Lengths


I have a masked textbox with the need to have a min/max length set on them. When these conditions are met a button becomes enabled.

I was thinking of handling the TextChanged event to determine the length of the entered text and set the buttons enabled value.

Is there a better approach?

 btnOK.Enabled = txtDataEntry.Text.Length >= MinDataLength && txtDataEntry.Text.Length <= MaxDataLength;

Solution

  • Which approach could be even simpler than what you are suggesting?

    myTextBox.Textchanged+=(s,o)=>{ myButton.Enabled = myTextBox.Length==10; };