Page 1 of 1

Change all text without selecting?

Posted: Thu Sep 18, 2008 2:15 am
by jnap
Hi,

I simply want to change the font of all the text without selecting anything from a ComboBox, is this possible?

I have only 4 Styles that ever need changing as this is an ASCII Art Viewer.

I have tried using: rve.ApplyTextStyle(0); but this has no effect.

Could someone please tell me how I can do this without selecting any text so that all the documents text is changed like in Notepad?

An example would be very much appreciated.

Many thanks

jnap

Posted: Thu Sep 18, 2008 10:28 am
by Sergey Tkachenko
ApplyTextStyle applies text to the selected text.
If you want an editing operation (undoable), this is the only way, to select and apply:

Code: Select all

RichViewEdit1.SelectAll;
RichViewEdit1.ApplyTextStyle(0);
If not, you have the following options (working both in TRichViewEdit and in TRichView):
1) You can change properties of styles without modifying document.
For example, to make all text red:

Code: Select all

for i := 0 to RVStyle1.TextStyles.Count-1 do
  RVStyle1.TextStyles[i].Color := clRed;
RichViewEdit1.Format;
2) Change all text styles. Assuming that all styles in document have the same value of Unicode property, and there are no tables in the document, the code is:

Code: Select all

for i := 0 RichViewEdit1.ItemCount-1 do
  if RichViewEdit1.GetItemStyle(i)>0 then
    RichViewEdit1.GetItem(i).StyleNo := 0;
RichViewEdit1.Format;
The code above changes only text items in the root document (not in table cells), it does not change font in tabulators and label items.

Posted: Thu Sep 18, 2008 3:10 pm
by jnap
Hi,

Thanks Sergey. I have changed it slightly to:

var
i: integer;
begin
for i := 0 to rve.ItemCount-1 do
if rve.GetItemStyle(i)>=0 then
rve.GetItem(i).StyleNo := CmbFont.ItemIndex;
rve.Format;

and now it works perfectly with a ComboBox!

Many thanks

jnap