StringBuilder will not display in TextBox (WinForms, C #)

I am trying to get the contents of a StringBuilder to display in the WinForms text box, but the window never appears when I try to compile the program. This is my first venture in WinForms and C #, and I have been using the language for about a week and a half, so this is probably a simple fix that I just can't see.

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { StringBuilder builder = new StringBuilder(); Random rand = new Random(); int[] builderList = new int[10000]; for (int i = 0; i < 10000; i++) { builderList[i] = rand.Next(1, 20000); builder.Append(builderList[i].ToString() + " "); } // This is the line that seems to be the problem... textBox1.Text = builder.ToString(); } } 

When I try to run the program and insert a breakpoint in this last line of code, I see that the program seems to just click this line continuously. Oddly enough, if I change this line to this:

 textBox1.Text = "Hey, lol"; 

my program will start. I checked the debugger in Visual Studio and saw that the contents of "builderList" were updated to random numbers, and the "builder" looks like it correctly stores the values ​​in "builderList" as a string, as I want, so I'm a little confused about that what is going on here. I would appreciate any help I can handle, as it seems like this should be relatively easy to fix, but I have still been at a dead end and I have not found anything useful in the MSDN documentation.

Many thanks!

+1
source share
2 answers

Change your TextBox1 as a MultiLine TextBox. Select "Allow multiLine"

enter image description here

+1
source

The real reason for this is the width of the pixel, check out my post and @TaW answer here: Maximum number of characters a TextBox can display

+1
source

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


All Articles