RichTextBox.ScrollToCaret problem

RichTextBox.ScrollToCaret problem

Post by Tony Davi » Sat, 01 Dec 2001 02:33:26



I have a RichTextBox in my application that receives messages asynchronously
from a background timer. As new messages are received, the new message is
added to the RichTextBox. I then want the new lines to be visible.

I found that the RichTextBox must have focus for this to work, so I wrote
the following code:

         m_wMsgRTF.Focus();
         m_wMsgRTF.SelectionStart  = m_wMsgRTF.TextLength + 1;
         m_wMsgRTF.SelectionLength = 0;
         m_wMsgRTF.ScrollToCaret();

This seems to work when the form that contains the RichTextBox has focus,
but does not if the form doesn't have focus. However, when you click on the
window, it then scrolls automatically to the correct position - kind of like
it's delaying the action until the parent form has focus, then it handles
the scroll (very irritating).

I want to be able to monitor messages entering the window without having to
go click it each time since another working window has focus 90% of the
time. Is there something I'm doing wrong, or is the a bug or what?
Also, is there a simpler way to force the RichTextBox to scroll to the
bottom?

Thanks,
Tony

 
 
 

RichTextBox.ScrollToCaret problem

Post by Peter Wu [Microsoft » Tue, 11 Dec 2001 15:51:08


Tony,

According to MSDN, this behavior is by design.

TextBoxBase.ScrollToCaret Method Scrolls the contents of the control to the
current caret position.

[Visual Basic]
Public Sub ScrollToCaret()
[C#]
public void ScrollToCaret();
[C++]
public: void ScrollToCaret();
[JScript]
public function ScrollToCaret();
Remarks
This method enables you to scroll the contents of the control until the
caret is within the visibile region of the control. If the caret is
positioned below the visible region of the control, the ScrollToCaret
method will scroll the contents of the control until the caret is visible
at the bottom of the control. If the caret is positioned above the visible
region of the control, this method scrolls the contents of the control
until the caret is visible at the top of the control. You can use this
method in a multiline text box to ensure that the current text entry point
is within the visible region of the control.

Note   This method has no effect if the control does not have focus or if
the caret is already positioned in the visible region of the control.

Thanks,

Peter Wu
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

 
 
 

RichTextBox.ScrollToCaret problem

Post by Tony Davi » Wed, 12 Dec 2001 03:14:29


Correct, so I set the control to have focus, but that still doesn't work
until the Form gets focus. It's a huge problem. MSN Messanger doesn't seem
to have this problem.

Tony



Quote:> Tony,

> According to MSDN, this behavior is by design.

> TextBoxBase.ScrollToCaret Method Scrolls the contents of the control to
the
> current caret position.

> [Visual Basic]
> Public Sub ScrollToCaret()
> [C#]
> public void ScrollToCaret();
> [C++]
> public: void ScrollToCaret();
> [JScript]
> public function ScrollToCaret();
> Remarks
> This method enables you to scroll the contents of the control until the
> caret is within the visibile region of the control. If the caret is
> positioned below the visible region of the control, the ScrollToCaret
> method will scroll the contents of the control until the caret is visible
> at the bottom of the control. If the caret is positioned above the visible
> region of the control, this method scrolls the contents of the control
> until the caret is visible at the top of the control. You can use this
> method in a multiline text box to ensure that the current text entry point
> is within the visible region of the control.

> Note   This method has no effect if the control does not have focus or if
> the caret is already positioned in the visible region of the control.

> Thanks,

> Peter Wu
> Microsoft Corporation

> This posting is provided "AS IS" with no warranties, and confers no

rights.
 
 
 

1. Having problems with ScrollToCaret()

Hi! i have this problem with my textbox. I would like my
textbox to scroll down to the new message received.
However, i'm unable to use ScrollToCaret() in compact
framework.

2. Acorn RiscOS

3. RichTextBox Problem #2 (some mistake)

4. aux async port

5. RichTextBox problem with IME.

6. How do I 'talk' to the modem?

7. RichTextBox problems...

8. AS/400 opportunities in Chicago, IL

9. Selection problem with RichTextBox

10. RichTextBox, DragDrop Problem

11. RichTextBox Font problem

12. RichTextBox RTF Problems