Disable MaxLength property for TextBox in C #

I am currently working on a Windows Forms application, and I need to have a TextBox that does not limit the input size to Int32.MaxValue .

The problem is that MaxLength is an Int32 property on a TextBox , and of course I cannot set a number that is greater than its value.

Ideally, I do not want to set any number and completely "disable" this check.

Is there a way that I can have a TextBox that doesn't limit the size of the input?

+3
source share
2 answers

Set it to zero

Windows NT 4.0, Windows 2000, Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note. If the MaxLength Property is set to 0, the maximum number of characters the user can enter 2147483646 or the amount based on available memory, whichever is less.

Windows Millennium Edition Note If the MaxLength property is set to 0, the maximum number of characters that the user can enter is 32,766 or the amount based on available memory, whichever is less.

From: http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.maxlength.aspx

EDIT for window forms

+11
source

The int.MaxValue limit int.MaxValue in any case unattainable. You cannot create a string for almost such a long time. In other words, if you really need more than 2 31 you have more problems than TextBox.MaxLength .

May I ask when you think it will actually be a rewarding experience to have more than 2 GB of ASCII text file in one GUI control? If you want to write a complete text editor that can handle huge files, you probably don't want to use a TextBox to get started ...

EDIT: I would actually argue that you probably want to set a limit less than int.MaxValue determined through testing - it is likely that the other bits of your system will fail before you approach that limit. Think about what the real limit is if you want, but I guarantee that it will be below int.MaxValue ...

+5
source

Source: https://habr.com/ru/post/1202008/


All Articles