I'm writing a simple debug console application that displays debug messages in a seperate application

The app contains a RichTextBox control to display the text. Vertical scrolling is on. After adding text to the control, I set the text selection to be the last character of the text so that the control will scroll to always display the new text at the bottom of the control

Problem is, the textbox doesn't scroll to the bottom while the console is not the foreground application. New text will be drawn when added (if it's already visible) and the scrollbar updates to show that there's more text in the control. When I bring the console forward, it THEN scrolls to the bottom of the text

I've tried calling textbox.ScrollToCaret(), textbox.Refresh(), and textbox.Update(). None of these help

Can anybody tell me how to get my TextBox control to scroll while in the background

TIA

Steve Johnso
Paris Developmen

Re: Scrolling a TextBox when form isn't in foreground? by hirf-spam-me-here

hirf-spam-me-here
Fri May 14 14:31:08 CDT 2004

* =?Utf-8?B?QmxhdHd1cnN0?= <anonymous@discussions.microsoft.com> scripsit:
> When using a RichTextBox control for displaying logging information, it is
> useful to scroll the recently added line into view. There are two ways to
> accomplish this:

Untested:

\\\
Private Const WM_VSCROLL As Int32 = &H115
Private Const SB_BOTTOM As Int32 = 7

Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Sub AddLine(ByVal Destination As RichTextBox, ByVal Text As String)
With Destination
.AppendText(Text & ControlChars.NewLine)
SendMessage(Destination.Handle, WM_VSCROLL, SB_BOTTOM, 0)
End With
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: Scrolling a TextBox when form isn't in foreground? by anonymous

anonymous
Fri May 14 23:01:04 CDT 2004

That works great! Thanks Herfried!!