Is there way to speed up displaying a lot of text in a winforms textbox?

前端 未结 7 1013
天涯浪人
天涯浪人 2020-12-21 14:32

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 (TextB

7条回答
  •  余生分开走
    2020-12-21 14:53

    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.

    Update

    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.

提交回复
热议问题