Google Grupper har inte längre stöd för nya Usenet-inlägg eller -prenumerationer. Historiskt innehåll förblir synligt.
Dismiss

'textBox' Behavior

5 visningar
Hoppa till det första olästa meddelandet

Chad Christensen

oläst,
30 juni 2003 14:03:002003-06-30
till
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.


Claes Bergefall

oläst,
1 juli 2003 08:58:512003-07-01
till
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

"Chad Christensen" <Chad.Chr...@hill.af.mil> wrote in message
news:u4DdZHzP...@TK2MSFTNGP10.phx.gbl...

Chad Christensen

oläst,
1 juli 2003 10:19:062003-07-01
till
I am using a trial version of Visual Studio .NET which is the .NET Framework
1.1. I don't have 1.0 so I have no idea if it works or not in 1.0. I also
tried a RichTextBox and it works with no limits on MaxLength using the
AppendText() function, but the box always shows the start of the output as
more text is being added to the box. I have tried using the ScrollToCaret()
function and it does no good!

How do I always display the end of the output as it's being added? I can't
believe this is so hard. This is such a common thing to do, i.e. show the
output as it's being added at the bottom and not the top. This is very
frustrating to me because it should be so simple. Any help would be
appreciated. :)

Thanks,

Chad Christensen


"Claes Bergefall" <claes.berge...@frontec.se> wrote in message
news:%23vLz$B9PDH...@TK2MSFTNGP10.phx.gbl...

Claes Bergefall

oläst,
2 juli 2003 03:56:242003-07-02
till
In order for ScrollToCaret to scroll to the end you must
first set the caret at the end. Set the SelectionLength property
to 0 and the SelectionStart property to the length of the text
before calling ScrollToCaret

If you still want to use a TextBox you can always bypass
the framework and send the messages directly to it. Try this
(whatch for line wrapping)

Public Const EM_REPLACESEL As Integer = &HC2
Public Const EM_SETMODIFY As Integer = &HB9

Public Overloads Declare Auto Function SendMessage Lib "User32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal msg As Integer, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As Integer

Public Overloads Declare Auto Function SendMessage Lib "User32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal msg As Integer, _
ByVal wParam As IntPtr, _

<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.Unm
anagedType.LPTStr)> ByVal lParam As String) As Integer

Private Sub AppendText(ByVal textBox As TextBox, ByVal text As String)
If textBox.IsHandleCreated Then
textBox.Select(textBox.TextLength, textBox.TextLength)
SendMessage(textBox.Handle, EM_REPLACESEL, New IntPtr(-1), text)
SendMessage(textBox.Handle, EM_SETMODIFY, New IntPtr(0),
IntPtr.Zero)
Else
textBox.AppendText(text)
End If
End Sub

/claes


"Chad Christensen" <Chad.Chr...@hill.af.mil> wrote in message

news:eUy7#u9PDH...@tk2msftngp13.phx.gbl...

Chad Christensen

oläst,
2 juli 2003 16:54:432003-07-02
till
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


"Claes Bergefall" <claes.berge...@frontec.se> wrote in message

news:uusMq9G...@TK2MSFTNGP10.phx.gbl...

0 nya meddelanden