Now I saw a problem: StringBuilder will not display in TextBox (WinForms, C #) . The author of the message could not display its contents, which is a string of about 50 thousand characters in a single line of a TextBox .
The response indicated that it should change the MultiLine property to true . The explanation is given in the comment:
Since iterating 10,000 times, the generated line is large and does not appear in the text field of one line.
So, I'm curious that the length max can be displayed in a text field with one line .
I looked through SO and found this question: The maximum number of TextBox characters (this is not MaxLength) , it eliminates some doubts, but not all. I still want to know:
- Since the
Text property is of type String , why can't it even handle 50k characters if MultiLine is false ? - How many characters a
TextBox can be held if MultiLine false ? Do we have a way to get this number? - Why does the
MultiLine property affect this feature?
For the first part of question 2, I checked the following things:
I suspected this length was due to memory allocated for the Text property. I did some research on the Internet and this MSDN Documentation gave me some ideas:
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 a user can enter is 2147483646 or the amount based on available memory, whichever is less.
So, I did an experiment: I created 2 TextBox , namely textBox1 and textBox2 . textBox2 displays the number of real-time textBox1 . In addition, I changed the MaxLength property to 0 for the TextBox . The code is as follows:
public Form1() { InitializeComponent(); textBox1.TextChanged += (s, e) => textBox2.Text = textBox1.Text.Length.ToString(); }
It turned out that when the length of the text exceeds 43679 , Text completely went away:


Thus, the memory allocated for the Text property may contain 43679 characters on my computer . But I'm not sure that this number is the same for all computers. Do we have a more sophisticated way to get this number?
Thanks in advance!