It is important to note that using MaxLength
alone (with no other properties to add, just like the other answers) works ONLY for projects in .NET Framework 4.5 and above.
I'm using 4.5, and it worked for my project
TextBox.MaxLength Property (MSDN Documentation)