Actually, in the upcoming 1.7 build, this has been added the the SF textbox. There is a property called AutoAdjustMaxLength on the textbox that will do this for you when using SF data binding.
But for reference purposes, you can do this on a BO:
Dim maxLength As Integer = MyBO.FieldLengths("MyFieldName")
or in C#
int maxLength = MyBO.FieldLengths["MyFieldName"];