I’m using a System.Windows.Forms.TextBox. According to the docs, the MaxLength property controls the amount of characters enter a user can type or paste into the TextBox (i.e. more than that can be added programmatically by using e.g. the AppendText function or the Text property). The current amount of characters can be got from the TextLength property.
- Is there any way to set the maximum amount of characters without making a custom limiter which calls
Clear()when the custom limit is reached? - Regardless, what is the absolute maximum it can hold? Is it only limited by memory?
- What happens when the maximum is reached / memory is full? Crash? Top x lines is cleared?
- What would be the best way to manually clear only the top x lines? Substring operation?
edit: I have tested it to hold more than 600k characters, regardless of MaxLength, at which point I manually stopped the program and asked this question.
AppendTextandTextin a derived class. See code below.Textproperty is a plain old string (private fieldSystem.Windows.Forms.Control::text). So the maximum length is the max length of a string, which is “2 GB, or about 1 billion characters” (see System.String).Linesproperty, but beware that every time you call it your entiretextwill be internally parsed into lines. If you’re pushing the limits of content length this would be a bad idea. So that faster way (in terms of execution, not coding) would be to zip through the characters and count the cr / lfs. You of course need to decide what you are considering a line ending.Code: Enforce
MaxLengthproperty even when setting text programmatically: