Viachaslau Tysianchuk
Viachaslau Tysianchuk

Reputation: 1690

Control to view a file with a large amount of text

Is there a TextBox-like WinForms control that can show a large amount of text (hundreds of megabytes) in read-only mode? Of course it should work without loading the whole file into memory at once.

I'm trying to implement this myself, using a standard TextBox, processing scroll and keyboard events and reading the amount of text necessary to fill the visible "window". But it's still quite buggy, and I'm feeling that I'm reinventing the wheel.

Upvotes: 1

Views: 3941

Answers (5)

Coman Paul
Coman Paul

Reputation: 301

Display the text in parts.....10.000 characters in each text box....i recently discovered thet if you make the textbox bigger the program will run faster when editing the text or scrolling...

Upvotes: 0

Oliver
Oliver

Reputation: 45101

I think you got best chances by using Scintilla or its wrapper Scintilla.Net. I think it doesn't it job that perfect, but it makes it much better than TextBox or RichtTextBox.

Upvotes: 2

Callum Rogers
Callum Rogers

Reputation: 15829

Loading "hundreds of megabytes" of text into a control sounds like a very, very bad idea memory/performance wise; it will likely crash your program. Anyway, how are you going to read all those millions of lines? Do you really need the whole text in there all the time? Mabye it would be better if you had a buffer and loaded small amounts of text into a RichTextBox and when you reach the end (or even near the end), simply load up the next 100 (or any other amount) of lines. Or, if you are searching for something, search for your keywords and put the relevant text in the RichTextBox. It really depends on what you are planning to do.

Upvotes: 2

arbiter
arbiter

Reputation: 9575

There is no such control from what I know. Long time ago I have written similar control but it is for Delphi, but the principles are the same (read limited block of data and render it). So if you decided to implement it by yourself, then move away from TextBox control, it is not well suitable for such needs. I believe you should create new Control descendant with all custom painting. It is not very easy, but it is the only correct way.

Upvotes: 0

Ksempac
Ksempac

Reputation: 1892

I've no knowledge of such a control (RichTextBox is slow when you put a single wikipedia page into it, so I'm quite sure he loads everything into memory).

My experience with the winforms is that you often need to customize defaults controls to obtain the behavior you want, even when it seems trivial (nullable DateTime anyone ?). On the other hand, they do offer a good base to add one or two simple behaviors quickly without having to do all by yourself.

I've been using winforms controls for several months and often ended up implementing specific (some trivial, others complex) behaviors in my own controls.

Upvotes: 0

Related Questions