Paragraph Styles

[Top]  [Chapter]  [Previous]  [Next]

A paragraph style includes font, color and spacing settings applied to an entire paragraph. The attributes of the style will only be used, if they were not "overridden" by either the paragraph attributes or the character attributes.

 

This code creates a new style:

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPParInterface PAttr = Memo.CurrStyle;

            IWPAttrInterface CAttr = Memo.CurrStyleAttr;

 

            Memo.SelectStyle("Heading1");

            PAttr.IndentLeft = 1440;

            CAttr.SetFontface("Tahoma");

            CAttr.SetFontSize(12);

 

 

With this code the current or the selected paragraphs will use the new styles:

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPParInterface Attr = Memo.CurrPar;

 

            Attr.SetProp(1, 1); // --> Work with selection

            try

            {

                Attr.StyleName = "Heading1";

                Attr.ClearCharAttr();

            }

            finally

            {

                Attr.SetProp(1, 0);

            }

            Memo.Reformat();

            wpdllInt1.Focus();

 

Please note that the attributes in a style are only used, if they are not overridden by the paragraph or character attributes. Here we use ClearCharAttr to make sure, the characters do not have their own attributes.

 

For a more selective control apply the style using ParStrCommand( 9, x, name ). If bit 1 is set in X, the character attributes, which are used by the selected style, are cleared, if bit 2 is set, the paragraph attributes are cleared.

 

So, we should better use this code:

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPParInterface Attr = Memo.CurrPar;

 

            Attr.SetProp(1, 1); // work with selected text

            try

            {

                // Select the style and remove the attributes which would 

                // otherwise override the setting in the style sheet

                Attr.ParStrCommand(9, 3, "Heading1");

            }

            finally

            {

                Attr.SetProp(1, 0);

            }

            Memo.Reformat();

            wpdllInt1.Focus();


[paragraph_styles.htm]    Copyright © 2007 by WPCubed GmbH