Jump to content
  • Advertisement
Sign in to follow this  
Toolmaker

[.net] RichEdit going nuts on me?

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

If you intended to correct an error in the post then please contact us.

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();

	SetupReceiveCallback();
}
Toolmaker

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by jods
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


++Rating for you sir, thank you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!