views:

121

answers:

3

I need to open a text file with ~4MB in a RichTextBox, but the end of the text was "trimmed".

How do I override a RichTextBox.MaxLength Int32 limit?

A: 

I'm not sure how much text RichTextBox can handle, but I believe MaxLength only applies to text the user enters. If you set .Text directly it should be able to go past MaxLength, unless MaxLength is already at the maximum.

Nelson
nope, the limit applies on the RTB.Text property as well
Keyo
See: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.maxlength.aspx, specifically the yellow box. Oh wait, I'm confused. If you set the text in the designer, then it works? But I think technically it's still set at "run time", just from the .designer file. Anyway, that website also says 64K which is obviously less than 4MB.
Nelson
So the question becomes, what are you trying to achieve? Most modern text editors load parts of the file at a time. When you scroll, they load the rest of it. Because of that, "opening" a huge file is almost instant. This is in contrast with Notepad which can hang while it loads a big file. With Rich Text it would be trickier, because you might have all the text bolded from the beginning, but you wouldn't know that if you only load pieces...
Nelson
Thanks, I'm gonna try to load the text in pieces.
Keyo
Just remember if you have formatting that goes past your current piece, you may run into trouble. I'm not sure what is usually done to prevent this problem.
Nelson
+1  A: 

The default for RichTextBox.MaxLength is 2GB, so with a 4MB file this is not going to be your problem.

Foxfire
The limit is 2147483647Unfortunally, my 4MB text file contains more characters than this.
Keyo
Erm, no, you can't stick 2 billion in a 4 million pound bag.
Hans Passant
You're probably thinking about the maximum size of string
Nelson
The default size of RichTextBox.MaxLength is exactly the same as the maximum size of string. Actually that makes pretty much sense, doesn't it ;)
Foxfire
You're right, I was confusing KB, number of characters, etc.
Nelson
A: 

Besides that, you can set the text limit(max limit is limited by your memory) by setting its length, something like:

if (textToAdd.Length > richTextBox1.MaxLength)

...it doesn't sound good loading that much amount of data in the box; you may run into out of memory hiccups!

This answer may help.

--EDIT--

Must, if you load, then you can load chunks from the file. And as user clicks the scroll button(up/down) load that chunk of the file; sounds like some code - but Must, if you load! Just thinking!

KMan