RichTextBox-LoadFile & Find

L

Levend Sayar

Hi, evereybody

I am loading a nearly 22 MB text file into a richtextbox control. It has ~
410K lines. First question, is there any faster way of loading this file
instead of doing it with LoadFile function? The second, using Find function
for text search again slower according to other windows apps. Is there any
way to make these faster?

AFAIK,dotnet generates intermediate code, but after it is just-in-time
compiled, it must be as fast as native code.

TIA,
Levend
 
M

Morten Wennevik

Hi Levend,

Instead of loading the entire file, why not only read enough lines to fill the textbox and read new lines when scrolling. It will require some more code, but it will be much much faster, and the size of the file is irrelevant (well, you may want to browse through the entire file at load time to calculate scroll sizes, number of lines, etc).

Happy coding!
Morten Wennevik [C# MVP]
 
L

Levend Sayar

Hi, Morten

Your suggestion can be a solution for LoadFile bottleneck, but I am also
giving search capability to the user. So he/she can search for a text.
Without loading entire file, richtextbox.find can't be used. Am I wrong ?

Levend
 
M

Morten Wennevik

No, the Find method will only locate text that the RichTextBox holds. The whole idea with the partial read solution is that the textbox only holds a small portion at any one time, so you will have to make your own Find method to search the file.

Happy coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top