# [.net] RichEdit going nuts on me?

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently using the RichEdit control for a small client for my current project. All is fine, until the displayed data goes BELOW the bottom of the richedit. My problem is, the richedit does not scroll down after I added the data. So, I tried using ScrollToCaret() on the richedit box, but this doesn't work. Is there a way to force the control to scroll to the bottom? Oh, I used this code:
if (bytesRecv > 0)
{
string data = Encoding.ASCII.GetString(receiveBuffer, 0, bytesRecv);

// Append text, set focus to the control, do some selection and force it to ScrollToCaret
richOutput.AppendText(data);
richOutput.Focus();
richOutput.SelectionStart = richOutput.Text.Length;
richOutput.SelectionLength = 1;
richOutput.ScrollToCaret();

}

Toolmaker

##### Share on other sites
Simple trick: if you give focus to the RichBox before calling AppendText, then it will automatically scroll to bottom.

Now, maybe you'd like to preserve focus (or simply not change it, since it implies validation, etc.). Here's a snippet of Interop that I use, you may find it useful:

[source lang=c#]        private const int WM_VSCROLL = 0x115;        private const int SB_BOTTOM = 7;        [System.Runtime.InteropServices.DllImport("User32")]        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);        private void ScrollToLastLine()        {            SendMessage(richbox.Handle, WM_VSCROLL, SB_BOTTOM, 0);        }

(The fact is that .NET doesn't support programmatically scrolling a RTB yet.)

[Edited by - jods on June 13, 2005 10:02:07 AM]

##### Share on other sites
I tried doing that, but it still refuses to work. The Version of richedit I'm using is: 1.1.4322.2032.

I have no idea why this is going wrong, as everyone appears to be claiming that this should work.

EDIT: I doesn't appear to be getting the focus, event though I call Focus() on the control.

Toolmaker

##### Share on other sites
Have you tried the interop solution also (I've edited my post). This should work, for sure.

The other solution will not work if your control cannot get the focus. This could be the case, e.g. if you've disabled it.

Good luck,
jods

##### Share on other sites
Quote:
 Original post by Toolmaker richOutput.SelectionStart = richOutput.Text.Length; richOutput.SelectionLength = 1; richOutput.ScrollToCaret();

The Length property returns the number of characters in the text box, which will be one greater than the maximum legal index for the selection caret. I'm not sure if this has an impact on the selection point, but a legal value is always better than an illegal one. =)

##### Share on other sites
Quote:
 Original post by jodsHave you tried the interop solution also (I've edited my post). This should work, for sure.The other solution will not work if your control cannot get the focus. This could be the case, e.g. if you've disabled it.Good luck,jods

++Rating for you sir, thank you.

##### Share on other sites
I'm glad I could help, thank you. :D

1. 1
2. 2
frob
14
3. 3
4. 4
5. 5
Rutin
12

• 12
• 10
• 57
• 14
• 15
• ### Forum Statistics

• Total Topics
632113
• Total Posts
3004183

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!