Board index » cppbuilder » TRichEdit Scrolling Question

TRichEdit Scrolling Question


2005-01-31 07:26:03 PM
cppbuilder2
Hi All,
This question may be the dumbest you have ever seen but for some reason
I don't seem to be able to work this out ????
I have a Rich Edit on a form, it is set to read only, as serial data is
recieved from the Comm Port I add this data to the RichEdit, when the
Rich edit window is full it adds a scroll bar and the data dissapears
off the screen. To view the data you need to use the scroll bar.
What I want to do is have the Rich Edit automatically scroll with the
data, for example if you had a list box and you wanted the same
functionality you would have some code like the following
void __fastcall TMainForm::AddSerialDataToList(String SerialData)
{
// Add Data to list
ListBox1->Items->Add(SerialData);
// if more than 1000 items are in the list remove the first
// as we only need to keep the last 1000 items
if(ListBox1->Count>1000)
ListBox1->Items->Delete(0);
// scroll list box so most current data is shown as it
// arrives in the list box
ListBox1->ItemIndex = ListBox1->Count - 1;
}
I am using a Rich Edit because I want to highlight the delimeters of the
data that I have received as well as bad data and specific data streams
in different colurs.
Can this be done with a TRichEdit and if it can how?
Many thanks in advance
Joe
 
 

Re:TRichEdit Scrolling Question

Joe Black < XXXX@XXXXX.COM >wrote:
Quote

[...] Can this be done with a TRichEdit and if it can how?
All you have to do is position the caret and then send it a
EM_SCROLLCARET message:
RichEdit1->Lines->Add( "Something" );
RichEdit1->SelStart = RichEdit1->GetTextLen();
RichEdit1->Perform( EM_SCROLLCARET, 0, 0 );
~ JD
 

Re:TRichEdit Scrolling Question

JD wrote:
Quote
Joe Black < XXXX@XXXXX.COM >wrote:

>[...] Can this be done with a TRichEdit and if it can how?


All you have to do is position the caret and then send it a
EM_SCROLLCARET message:

RichEdit1->Lines->Add( "Something" );
RichEdit1->SelStart = RichEdit1->GetTextLen();
RichEdit1->Perform( EM_SCROLLCARET, 0, 0 );

~ JD

Hi JD,
That worked a treat, thanks again.
Joe
 

{smallsort}