Is there way to speed up displaying a lot of text in a winforms textbox? My application reads a file (which can be as large as 20MB) and then displays it to a textbox (TextBoxX.Text = fileText;).
The process of displaying the text is extremely slow, it sometimes takes up to a few minutes. The problem is that this application is designed to show a lot of text in a file, quickly to the user.
Is there any way to do this faster? Maybe use some kind of caching?
The Text
property is evil if you like to put lot of text into a TextBox
. Instead you should read the file in chunks and add them by using the AppendText()
function.
If you go further and put your file read process into a BackgroundWorker
that reads in the file line by line and then reports each line in ReportProgress, you could implement there the AppendText() and it should do everything much smoother.
After some coding and testing i have to admit that the above described approach sounds good, but the TextBox needs so much rendering time after each AppendText()
that this just doesn't work.
But if you have no problem about using 3rd party controls you should take a look at Scintilla.Net. It has no problems with big text files and performs really better in these cases.