TextBox MaxLength problems. Is it a bug in Framework 1.1?

D

DalePres

Still no answer to this question, but since I originally posted it, I have
created a separate application for test and verified the operation is just
like I state here. The code for the test is at the bottom.

By default, the MaxLength for a multi-line TextBox is supposed to be

4294967295 characters in all the NT based OS's and 65535 in the 9x based

OS's.

I have an application where I use a multi-line textbox (or tried to use a

textbox but gave up) on Windows XP. The textbox is used for displaying

application log information and grows fairly rapidly. The problem is that

once the contents length gets to 32767, it never gets any longer, even

though I have set MaxLength to 250000.

When I substitute a RichTextBox in the same application with no other

changes in code other than the type, the app works fine and the RichTextBox

stores up to 250000 characters.

Is this a known bug in the version 1.1 framework or is there something I may

be missing?

Thanks for your input,

Dale

private void fillText_Click(object sender, System.EventArgs e)

{

for (int count = 0; count < int.Parse(textBox2.Text); count++)

{

textBox1.AppendText("Here is another line of text; How many will it hold?" +

(char)13 + (char)10);

label1.Text = textBox1.Text.Length.ToString();

}

}

Another interesting question is why do I have to use (char)13 + (char)10?

Adding "\n" at the end of my text string leaves two square boxes at the end

of the string but doesn't start a new line. "\r\n" starts a new line but

leaves two square boxes at the end of each line; only (char)13 + (char)10

gives a clean new line operation.
 
E

Ed Kaim [MSFT]

I'm using Windows XP too (which is surprisingly left out of the remarks
section of the documentation of MaxLength). I find that using AppendText
limits to the length of a signed word (2^16 - 1 = 32767), whereas using Text
+= isn't constrained. I don't know why this is, especially since the
AppendText documentation implies that it's an equal alternative to the
other.

As for the newlines, I'm finding that using \n results in a newline after a
blank box, whereas \r\n works fine for both.

Oddly, I also found that if you do an AppendText with \n, you get the box
and a newline, but if you then do a += with \n, it removes all newlines from
the textbox, leaving all text lines separated by boxes on a single line.

I'm not sure what your goals are, but I hope this helps you get something
that works.
 
D

DalePres

There must not be that many people using AppendText I guess; and you know
how we hate += in handling strings.

But anything that works, works for me. There is one problem though. If I
limit the number of iterations to keep the total length just under 32767 for
testing purposes (about 600 iterations for my test string) it takes
approximately 2.6 seconds for += and only 1.05 seconds for AppendText. The
two methods aren't equal alternatives. AppendText is much quicker.
 
H

Herfried K. Wagner [MVP]

* "Ed Kaim said:
I'm using Windows XP too (which is surprisingly left out of the remarks
section of the documentation of MaxLength). I find that using AppendText
limits to the length of a signed word (2^16 - 1 = 32767), whereas using Text
+= isn't constrained. I don't know why this is, especially since the
AppendText documentation implies that it's an equal alternative to the
other.

ACK. I can repro that too (Windows XP Professional + .NET 1.0).
As for the newlines, I'm finding that using \n results in a newline after a
blank box, whereas \r\n works fine for both.

I would use 'Environment.NewLine'...
Oddly, I also found that if you do an AppendText with \n, you get the box
and a newline, but if you then do a += with \n, it removes all newlines from
the textbox, leaving all text lines separated by boxes on a single
line.

Really odd.
 
H

Herfried K. Wagner [MVP]

* "DalePres said:
There must not be that many people using AppendText I guess; and you know
how we hate += in handling strings.

But anything that works, works for me. There is one problem though. If I
limit the number of iterations to keep the total length just under 32767 for
testing purposes (about 600 iterations for my test string) it takes
approximately 2.6 seconds for += and only 1.05 seconds for AppendText. The
two methods aren't equal alternatives. AppendText is much quicker.

You may want to concatenate the string in a 'StringBuilder'. Maybe
that's what 'AppendText' does.
 

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