Updated 11.02.16
How can I display large (several hundred megabytes) text in a form? TextBox and RichTextBox do not cope with a similar volume.
Here are some simple code examples for demonstration:
StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10000000; i++) { sb.Append(i); sb.Append('\n'); } this.textBox1.Text = sb.ToString(); The cycle of forming the line is performed fairly quickly (seconds), but on transferring text to the TextBox, everything rises tightly, there was enough patience for 5 minutes, then it stopped forcibly.
string[] lines = string[10000000]; for (int i = 0; i < 10000000; i++) { lines[i] = i.ToString(); } this.textBox1.Lines = lines; The result is similar
StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10000000; i++) { sb.Append(i); sb.Append('\n'); } this.richTextBox1.Text = sb.ToString(); The result is slightly better, the control is filled and even drawn, but when scrolling the text it also freezes after the first hundred lines.
There are two problems:
- organizing a buffer suitable for reading / writing to a file and editing in a
TextBox; - organization of the correct operation of the vertical scrolling
TextBox, taking into account the size of the file, and not just the displayed fragment.
"Excavations" in the documentation did not give any useful result. So far, only one idea has arisen: read the file into an array of strings and give it to the TextBox in portions, but at the same time I don’t understand how to force the native TextBox display the actual file size and perform the movement accordingly.
Another option is to build your “bike” with “Preference and Young Ladies”, but I would not like it if there are solutions for standard controls. In any case, I will not give up ideas on how to organize text editing and related tasks, such as tracking and fixing the cursor position in the control.
EnSO was also dug up in search of an answer, one of the recommendations is to use special software for this. But if there is such software, then the problem is still solved.
TextBox? I'm not sure about WinForms, but WPFTextBoxnot intended for huge amounts of text. - VladD