(Solved) Making a Rich Text Box Scroll to the Appened Text

Started by
9 comments, last by Zmurf 18 years, 9 months ago
How can I get my Rich Text Box to automatically scroll down the the text i've just appened to it. Whenever I appened text to it and the text is below the visible text area it just stays there and you have to manual scroll dow nto see it. I tried richTextBox->ScrollToCaret, but I can't figure out how to make the caret move to the end of the text in the box. Any ideas? [Edited by - Zmurf on July 27, 2005 6:09:36 AM]
If it's possible for us to conceive it, than it must be possible.
Advertisement
I'm not sure if this will work for you, but I used this with a normal edit control and sorry I am not at home to glance at the SDK Documentation but this is what I have for appending text to the end and having it show:



SendMessage( hEditControl, EM_LINESCROLL, 0,
(LPARAM)(int)(SendMessage(hEditControl, EM_GETLINECOUNT, 0, 0) - 1) );



hEditControl is the handle of the edit(rich edit in your case) control.


-David
This works for me:

    // Scroll to the bottom    SendMessage(m_richEdit, WM_VSCROLL, SB_BOTTOM, 0);    // Set the caret to the bottom of control and scroll to it    SendMessage(m_richEdit, EM_SETSEL, std::numeric_limits<int>::max(), std::numeric_limits<int>::max());    SendMessage(m_richEdit, EM_SCROLLCARET, 0, 0);
I'm using Visual Studio .Net, I implemented the code, and I'm getting new errors that are totally irelevant to the code I added, there not even in the same document. ><

Quote:c:\Documents and Settings\Zmurf\My Documents\Visual Studio\Projects\Sticky\frmConnect.h(292) : error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'
stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager'
initSticky.cpp(6) : error C2731: 'WinMain' : function cannot be overloaded
initSticky.cpp(6) : see declaration of 'WinMain'
frmMain.cpp
c:\Documents and Settings\Zmurf\My Documents\Visual Studio\Projects\Sticky\frmConnect.h(292) : error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'
stdafx.cpp(0) : see declaration of 'System::Resources::ResourceManager'


Is it an MFC command? Bacause I don't use MFC (I don't think I'm going to learn either)
If it's possible for us to conceive it, than it must be possible.
Chances are you included <windows.h> (along with frmConnect.h), which is now defining:
WINGDIAPI int   WINAPI GetObjectA( IN HGDIOBJ, IN int, OUT LPVOID);#ifdef UNICODE#define GetObject  GetObjectW#else#define GetObject  GetObjectA#endif // !UNICODE

So it effectively takes over the name "GetObject" and replaces it with GetObjectA or GetObjectW, making the compiler confused when it sees your own GetObject method. I'm sure you can see this is very annoying :). Perhaps you could rename your GetObject method in frmConnect.h to something else?

And no, this is plain Win32 API, not using the MFC.
Lol, see this is what I don't understand. I haven't used a GetObject command in my application! I'm still fairly new to Visual Studio and Windows Forms programming, and this is the biggest project I've made so far.

I've gone to the help files and I've included <windows.h> and linked 'User32.lib' because it said they were dependencies and I still get these errors.
If it's possible for us to conceive it, than it must be possible.
Oh, you're using Windows Forms? Sorry, I assumed it was using the plain Win32 API.
I'm not sure about how to fix this problem in Winforms - the code I gave probably won't work :)
Damn ... ><
If it's possible for us to conceive it, than it must be possible.
Does anyone know how to do this?
If it's possible for us to conceive it, than it must be possible.
The way I've always done it is set the caret using richTextBox.SelStart = richTextBox.Text.Length , and then use ScrollToCaret.

This topic is closed to new replies.

Advertisement