Change font programmatically

General TRichView support forum. Please post your questions here
Post Reply
fatih
Posts: 5
Joined: Sun May 11, 2025 3:22 pm

Change font programmatically

Post by fatih »

Hello, I'm newbie. I want to change font settings programmatically. The code below works but RVFontComboBox1 doesn't respect the change. It still shows the default font name.

Code: Select all

RichViewEdit1.Style.TextStyles[0].FontName:='Times New Roman';
Any idea?
Sergey Tkachenko
Site Admin
Posts: 17836
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Change font programmatically

Post by Sergey Tkachenko »

After changing properties of TextSTyles, call RichViewEdit1.Format;
If the combobox is still not updated, call RichViewEdit1.CurTextStyleChange.
Sergey Tkachenko
Site Admin
Posts: 17836
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Change font programmatically

Post by Sergey Tkachenko »

By the way, if you want to change font for new documents in RichViewActions (File | New command, or for loaded text styles). it must be done differently depending on using StyleTemplates (named styles).

If you use named styles (RichViewEdit1.UseStyleTemplates = True), change properties of "Normal" style template in rvActionNew.StyleTemplates: assign its properties:
TextStyle.FontName = 'Times New Roman';
ValidTextProperties = [rvfiFontName];
You can do it at designtime using the Object Inspector (but please note that ValidTextProperties are available as ValidTextPropertiesEditor in the Object Inspector).

If you do not use style templates, use rvActionNew1.OnNew event, see the example in the topic https://www.trichview.com/help-actions/ ... _onnew.htm
Post Reply