Board index » delphi » Change Rich Text Contents without selecting text?

Change Rich Text Contents without selecting text?

Hi all,

I'm loading a RichEdit control with some text information and
then formatting it after the text is loaded. I scan the words
and underline and/or change the color based on the first few
letters of the word.

The problem is, as far as I can tell, the only way to format
text in the control is to manually select it first using
SelStart and SelLength, then apply the formatting. This
results in very ugly highlights appearing and disappearing
after the text is loaded.

I tried formatting the text in a second RichEdit off screen
and then copying the text into the "real" RichEdit, but all
my attempts have the text copying over without formatting.

Any way to format text in a RichEdit, after the text has
already been added, without directly selecting it?
Alternately, is there a way to copy text from one RichEdit to
another without losing the formatting? TIA.

 - Dave

 

Re:Change Rich Text Contents without selecting text?


David M. Fornalsky <cyg...@mcs.com> schrieb im Beitrag
<_Eu74.20640$k22.1364...@newscene.newscene.com>...

Quote
> Any way to format text in a RichEdit, after the text has
> already been added, without directly selecting it?
> Alternately, is there a way to copy text from one RichEdit to
> another without losing the formatting? TIA.

Copying the text from one richedit to another is quite simple. Use a
tmemorystream for it:

var
   m: tmemorystream;
begin
  m := tmemorystream.create;
  richedit1.lines.savetostream(m);
  m.seek(0,0);  //set pos to start
  richedit2.lines.loadfromstream(m);
  m.free;
end;

Quote
> The problem is, as far as I can tell, the only way to format
> text in the control is to manually select it first using
> SelStart and SelLength, then apply the formatting. This
> results in very ugly highlights appearing and disappearing
> after the text is loaded.

You can lock the window handle to avoid re-painting while you are applying
your changes:

begin
  LockWindowUpdate(richedit1.handle);

  //apply your changes

  PostMessage(richedit1.handle, WM_VSCROLL, MakeLong(SB_TOP, 0), 0);
//scroll back to top
  LockWindowUpdate(0);  //unlock handle
end;

--
Alexander Halser
+++++++++++++++++++++++++++++++++++++++
http://www.ec-software.com
Help & Manual - the next generation in help authoring

Re:Change Rich Text Contents without selecting text?


"David M. Fornalsky" schrieb:

Quote

> Hi all,

> I'm loading a RichEdit control with some text information and
> then formatting it after the text is loaded. I scan the words
> and underline and/or change the color based on the first few
> letters of the word.

> The problem is, as far as I can tell, the only way to format
> text in the control is to manually select it first using
> SelStart and SelLength, then apply the formatting. This
> results in very ugly highlights appearing and disappearing
> after the text is loaded.

You can hide this visual feedback and accelerate the whole thing, if you
bracket the formatting calls with Lines.BeginUpdate / Lines.EndUpdate.

-Michael

Other Threads