'textBox' Behavior

  • Thread starter Thread starter Chad Christensen
  • Start date Start date
C

Chad Christensen

I am having a strange problem associated with appending to a textBox using
C# .NET. I am running another program (using the 'Process' class) and the
standard output from the other program is being redirected somewhere else
using threads so I can display it in the Multiline textBox control.

I am sucessfully capturing all the standard output text from the other
program, but when I try to append text to the textBox control using the
AppendText() method, it only allows 32767 characters. In other words, it
just stops appending text at 32767 characters. I have set the 'MaxLength'
variable to a very high number and it does no good. Like I said, I am using
the AppendText() method (from the TextBoxBase class) so that the textBox
scrollbar position will be at the bottom and not always reset its position
at the top (so you can see the latest output text). If I don't use the
AppendText() method, it works just fine with no limits on the amount of
text, but always resets itself to the top so you don't see the latest text,
always just the beginning text.
 
I ran ILDASM and checked the code. Appearently the framework temporarily
sets the max length to 32767 (using a EM_LIMITTEXT message) before
appending the new text (using a EM_REPLACESEL message). After that
it resets the max length to the old value (i.e. to the value of the
MaxLength
property) again. This behaviour is new in 1.1 (I compared it to 1.0).
Does it work in 1.0?


Download Lutz Roeder's .NET Reflector (http://www.aisto.com/roeder/dotnet/)
if you want to see what's happening inside the framework (it's easier to
read than ILDASM)

/claes
 
Thank you for the suggestions Claes. I appreciate it. I tried your
suggestion for the ScrollToCaret() function and I still couldn't get it to
work as far as always seeing the latest text being added to the box. It
would still always reset its position to the top of the box as text was
being added. Oh well!

However, yesterday (July 1, 2003) I found a property called "HideSelection"
that is part of the TextBoxBase class and it makes the scrolling work as
expected (always seeing the latest text added to the box) if it is set to
False. The default for this property is True. So I finally found a
solution! I copied your code to bypass the framwork in case I ever need it.

Thanks again!

Chad Christensen
 
Back
Top