Change all text without selecting?

General TRichView support forum. Please post your questions here
Post Reply
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Change all text without selecting?

Post 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
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post 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
Post Reply