Page 1 of 1

How to keep previous font(with style) not change

Posted: Thu Mar 03, 2011 5:12 pm
by noibird
Hi,

I'm sorry to trouble you. But this problem have made me in puzzle for several days. I have one richviewedit and one richview, just like a chatbox. I want to copy content from richviewedit to richview with style which is defined by user(bold, size, etc.) while the font in richview should keep the prious style.

In my code, if I copy content from richviewedit to richview, the richview will apply the new style for the whole richview. The previous style will be changed. So, my question is how to keep previous font not change while adding new font with style to richview.

My code:

Code: Select all

	TStringStream		*sp = new TStringStream();

	edt1->SaveRVFToStream(sp, false);
	sp->Position = 0;
	rchvw1->InsertRVFFromStream(sp, edt1->ItemCount - 1);
	rchvw1->Format();
	edt1->Clear();
	edt1->Format();
	delete sp;
Any help is appreciate!

Posted: Thu Mar 03, 2011 5:18 pm
by noibird
// Change font
void __fastcall TForm1::cbb1Change(TObject *Sender)
{
edt1->SelectAll();
edt1->Style->TextStyles->Items[1]->FontName = cbb1->FontName;
edt1->ApplyTextStyle(1);
}

After changing font and then copy content to richview, the richview will apply the new font type to the whole richview.

Posted: Thu Mar 03, 2011 8:27 pm
by Sergey Tkachenko
Use ApplyStyleConversion (and OnStyleConversion event) instead of ApplyTextStyle.
Do not change properties of existing text styles, it will affect all text that use these style.

Examples:
1) Chat demo, see http://www.trichview.com/forums/viewtopic.php?t=63
The third demo (Advanced demo with rich text text input) does what you need. Unfortunately, only Pascal version.
2) Demos\CBuilder\Editors\Editor2\ (CBuilderUnicode instead of CBuilder for C++Builder 2009-XE) shows how to use ApplyStyleConversion.