Hi all.
I'm trying to set styles in code for an edit. I've managed to *almost* set the initial style like this:
procedure TForm1.FormCreate(Sender: TObject);
var
Style_1, Style_2: TWPTextStyle;
i: Integer;
begin
// Create a style:
Style_1 := WPRichText1.ParStyles.AddStyle('Test style');
Style_1.ASet(WPAT_Alignment, Integer(paralBlock));
Style_1.ASetFontName('Times New Roman');
Style_1.ASetColor(WPAT_CharColor, clRed);
Style_2 := WPRichText1.ParStyles.AddStyle('Another style');
Style_2.ASet(WPAT_Alignment, Integer(paralBlock));
Style_2.ASetColor(WPAT_CharColor, clBlue);
for i := 0 to WPRichText1.ParStyles.Count -1 do
begin
if WPRichText1.ParStyles[i].Name = 'Test style' then
WPRichText1.ParStyles[i].IsDefault := True;
end;
WPRichText1.ActivePar.ABaseStyle := Style_1;
end;
Alles anzeigen
Setting the ActivePar.ABaseStyle seems necessary, otherwise on an empty editor the first paragraph is not using that style, only the following ones.
Anyway, my problem is that the font is not Times New Roman in the editor. Color is red and the style dropdown correctly shows "Test style" as the selected style, but it is using Arial font.
Maybe I need to set the DefaultAttr or something like that? Btw, I've noticed that DefaultAttr doesn't work (or probably I don't use it correctly), instead I have to use WritingAttr to affect the defaults.
Is there a complete sample of something along the lines of setting styles in code and assigning the default one? Lots of pieces of information in the docs and this forum, but I'm still a bit lost...
TIA,
Antti Kurenniemi