Board index » cppbuilder » How can TRichEdit show his lines continuosly

How can TRichEdit show his lines continuosly


2003-12-16 08:04:57 PM
cppbuilder53
Hi,
I'd like to show the lines of a TRichEdit continuosly, from the first until
the last line
by code.
I use
SendMessage(TRichEdit1->Handle, WM_VSCROLL, SB_LINEDOWN, 0);
with a TTimer control with Interval = 650,
but the result is not so pretty.
I'd like a continuosly smoothed scrolling (like About windows of Dreamweaver
MX).
There's a way to do this?
TNX
Mario Sernicola
 
 

Re:How can TRichEdit show his lines continuosly

You can use this technique, based on a RichEdit control
Owned by a ScrollBox Parent. This is the code:
TScrollBox* ScrollBox1;
TRichEdit* RichEdit1;
const int SCROLL_DISTANCE_Y = 1; //Scroll Speed
const int RICHEDIT_HEIGHT = 1000;
const int SCROLLBOX_HEIGHT = 300;
const int NUMBER_OF_SCROLLS = 100;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Color = clBlue;
ScrollBox1 = new TScrollBox(this);
ScrollBox1->Parent = this;
ScrollBox1->Top = 10;
ScrollBox1->Left = 10;
ScrollBox1->Width = 225;
ScrollBox1->Height = SCROLLBOX_HEIGHT;
ScrollBox1->VertScrollBar->Visible = false;
ScrollBox1->HorzScrollBar->Visible = false;
RichEdit1 = new TRichEdit(ScrollBox1);
RichEdit1->Parent = ScrollBox1;
RichEdit1->Top = 0;
RichEdit1->Left = 0;
RichEdit1->Width = ScrollBox1->Width-2;
RichEdit1->Height = RICHEDIT_HEIGHT;
RichEdit1->Lines->Clear();
RichEdit1->Color = (TColor)0x00efd345;
for (int i = 0; i < 200; i++)
{
RichEdit1->Text = RichEdit1->Text + "This is a story "
+ IntToStr(i) + ". ";
}
RichEdit1->SelStart = 0; // move text cursor to top of edit
RichEdit1->HideScrollBars = true;
RichEdit1->Font->Name = "Times New Roman";
RichEdit1->Font->Size = 10;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int count = 0;
while(count++ < NUMBER_OF_SCROLLS)
{
if (abs(RichEdit1->Top) < RICHEDIT_HEIGHT-SCROLLBOX_HEIGHT)
{
ScrollBox1->ScrollBy(0, -SCROLL_DISTANCE_Y);
ScrollBox1->Refresh();
Sleep(20);
}
else
break;
}
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int count = 0;
while(count++ < NUMBER_OF_SCROLLS)
{
if (RichEdit1->Top < 0)
{
ScrollBox1->ScrollBy(0, SCROLL_DISTANCE_Y);
ScrollBox1->Refresh();
Sleep(20);
}
else
break;
}
}
//--------------------------------------------------------------------------
-
If you like you could use threads to produce an even smoother scrolling,
specially if
you intend to use big while loops.
Rodolfo
"Mario Sernicola" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I'd like to show the lines of a TRichEdit continuosly, from the first
until
the last line
by code.

I use

SendMessage(TRichEdit1->Handle, WM_VSCROLL, SB_LINEDOWN, 0);

with a TTimer control with Interval = 650,

but the result is not so pretty.

I'd like a continuosly smoothed scrolling (like About windows of
Dreamweaver
MX).

There's a way to do this?

TNX

Mario Sernicola


 

Re:How can TRichEdit show his lines continuosly

Thank you Rodolfo,
all runs perfectly, and your solution is very elegant (even if I've to spend
some lines of code :)
I think it's better if I calculate the height of TRichEdit depend on numbers
of lines and font height (of course ;)
Another question:
Can I change at runtime the font of a line or a portion of text in a
TRichEdit? I can do the same thing in Property Editor?
I've written every lines in my TRichEdit by Propery Editor, bt I'd like to
see "Credits", "License" and other text in bold font.
Thank you very much
 

{smallsort}

Re:How can TRichEdit show his lines continuosly

Mario Sernicola <mariosernicola>wrote in message
Quote
I've written every lines in my TRichEdit by Propery Editor, bt I'd
like to
see "Credits", "License" and other text in bold font.
Here is some real BCB3 code to bold the current line, where the line
number is in "line":
AsciiRE->SelStart=
AsciiRE->Perform(EM_LINEINDEX,(WPARAM)line,0);
AsciiRE->Perform(EM_SCROLLCARET,0,0); // Visible to user
AsciiRE->SelLength=
AsciiRE->Perform(EM_LINELENGTH,
(WPARAM)AsciiRE->SelStart,0);
AsciiRE->SelAttributes->Style=
AsciiRE->SelAttributes->Style << fsBold;
AsciiRE->SelLength=0;
AsciiRE->SelAttributes->Style=
AsciiRE->SelAttributes->Style>>fsBold;
Note that this "contaminates" the RichEdit Styles for reuse later, so
if the user starts over, I run:
// Clear out RichEdit and Bolding from prev Cue/Group/Sub
AsciiRE->Clear();
AsciiRE->SelectAll();
AsciiRE->SelAttributes->Style=
AsciiRE->SelAttributes->Style>>fsBold;
AsciiRE->SelLength=0;
AsciiRE->SelStart=0;
 

Re:How can TRichEdit show his lines continuosly

"Mario Sernicola" < XXXX@XXXXX.COM >wrote in message
Quote
Thank you Rodolfo,

all runs perfectly, and your solution is very elegant (even if I've to
spend
some lines of code :)

I think it's better if I calculate the height of TRichEdit depend on
numbers
of lines and font height (of course ;)

Another question:

Can I change at runtime the font of a line or a portion of text in a
TRichEdit? I can do the same thing in Property Editor?

I've written every lines in my TRichEdit by Propery Editor, bt I'd like to
see "Credits", "License" and other text in bold font.

Thank you very much
I wrote a component called Extended Rich Edit that has several write methods
Some of these methods can change the font of a portion of text.
www.geocities.com/rodolfofrino/ExtendedRichEdit.html
Rodolfo
 

Re:How can TRichEdit show his lines continuosly

Quote
Can I change at runtime the font of a line or a portion of text in a
TRichEdit? I can do the same thing in Property Editor?
Yes. Have a look at this code:
void __fastcall TForm1::Button4Click(TObject *Sender)
{
RichEditEx1->Lines->Clear();
RichEditEx1->Font->Size = 20;
RichEditEx1->Lines->Add("C++ Builder Version 5.0");
RichEditEx1->SelStart = 0;
RichEditEx1->SelLength = 4;
RichEditEx1->SelAttributes->Color = clRed;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsUnderline;
RichEditEx1->SelAttributes->Name = "Times New Roman";
RichEditEx1->SelStart = 4;
RichEditEx1->SelLength = 10;
RichEditEx1->SelAttributes->Height = 72;
RichEditEx1->SelAttributes->Color = clBlack;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsUnderline;
RichEditEx1->SelAttributes->Name = "Arial Black";
RichEditEx1->SelStart = 11;
RichEditEx1->SelLength = 12;
RichEditEx1->SelAttributes->Color = clYellow;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsItalic;
RichEditEx1->SelAttributes->Height = 30;
RichEditEx1->SelAttributes->Name = "MS Sans Serif";
}
Rodolfo
 

Re:How can TRichEdit show his lines continuosly

Thank you Rodolfo
I'll download your component at soon as possible!
Thank you very much
Mario Sernicola
 

Re:How can TRichEdit show his lines continuosly

Now that I looked again to my component I remembered that it cannot
change a portion of text *in the same line* of RichEdit. It only changes the
font in different lines.
However, having said that, the code I posted before, which I copy here
void __fastcall TForm1::Button4Click(TObject *Sender)
{
RichEditEx1->Lines->Clear();
RichEditEx1->Font->Size = 20;
RichEditEx1->Lines->Add("C++ Builder Version 5.0");
RichEditEx1->SelStart = 0;
RichEditEx1->SelLength = 4;
RichEditEx1->SelAttributes->Color = clRed;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsUnderline;
RichEditEx1->SelAttributes->Name = "Times New Roman"; //<==== font1
RichEditEx1->SelStart = 4;
RichEditEx1->SelLength = 10;
RichEditEx1->SelAttributes->Height = 72;
RichEditEx1->SelAttributes->Color = clBlack;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsUnderline;
RichEditEx1->SelAttributes->Name = "Arial Black"; //<======= font2
RichEditEx1->SelStart = 11;
RichEditEx1->SelLength = 12;
RichEditEx1->SelAttributes->Color = clYellow;
RichEditEx1->SelAttributes->Style =
RichEditEx1->SelAttributes->Style << fsItalic;
RichEditEx1->SelAttributes->Height = 30;
RichEditEx1->SelAttributes->Name = "MS Sans Serif"; //<===== font3
}
does different fonts *on a single RichEdit line*. One thing you could do
then, if you wish,
is to add a new write method to RichEditEx with the above functionality.
Rodolfo
"Mario Sernicola" < XXXX@XXXXX.COM >wrote in message
Quote
Thank you Rodolfo

I'll download your component at soon as possible!

Thank you very much

Mario Sernicola


 

Re:How can TRichEdit show his lines continuosly

This is the link to the threaded version of RichEdit with Smooth Scroll:
www.geocities.com/rodolfofrino/RichEditSmoothScrollWithThreads.html
Rodolfo