Font Attributes

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

In this topic we want to draw Your attention to various possibilities how to change the character attributes.

 

i.e. we want to insert the text "this is bold text".

 

Solution A) - here we simulate typing into the editor.

 

(please click on the highlighted names to get more information about the respective methods and the parameters)

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPTextCursor TextCursor = Memo.TextCursor;

            IWPAttrInterface Attr = Memo.TextAttr;

 

            Attr.Clear();

            Attr.SetFontface("Courier New");

            Attr.SetFontSize(11);

            TextCursor.InputText("this is");  

            Attr.IncludeStyles(1);

            TextCursor.InputText("bold");

            Attr.ExcludeStyles(1);

            TextCursor.InputText(" ");

            Attr.SetColorwpdllInt1.ToRGB(Color.Red) );

            Attr.IncludeStyles(4);

            TextCursor.InputText("text");

 

 

 BTW: To retrieve the current fore color use

         int rgb =0;

         if(Attr.GetColor(ref rgb)) 

         some_control.ForeColor = ColorTranslator.FromWin32(rgb);

 

 

Solution B) - change attributes of existing text.

 

Here we assume the text "this is bold text" has been already written to the document.

Now update the attributes of this text:

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPTextCursor TextCursor = Memo.TextCursor;            

            bool ok = false;

 

            int cp = TextCursor.MarkerDrop(0);

            // Use FindText.- If "MoveCursor=false", the text will be selected

            TextCursor.FindText("this is bold text", true, false, false, false, ref ok);

            if (ok)

            {

               // We need to initialize AFTER the selection in case we use TextAttr, 

               // alternatively we could use CurrSelAttr.

               IWPAttrInterface Attr = Memo.TextAttr; 

               Attr.Clear();

               Attr.SetFontface("Arial");

            }

            TextCursor.MarkerGoto(true, cp);

 

Please see IWPTextCursor.FindText for another example.

 

Solution C) - use CharAttr index values and the CurrParText interface to add text quickly.

 

Here we first create a set of index values which are used in Append.

 

            IWPMemo Memo = wpdllInt1.Memo;

            IWPDataBlock Block = Memo.ActiveText;

            IWPAttrInterface Attr = wpdllInt1.AttrHelper;

 

            int header1, header2, body;

            Attr.Clear();

            Attr.SetFontface("Arial");

            Attr.SetFontSize(11);

            Attr.IncludeStyles(1);

            header1 = Attr.CharAttrIndex;

 

            Attr.SetFontSize(10);

            header2 = Attr.CharAttrIndex;

 

            Attr.ExcludeStyles(1);

            body = Attr.CharAttrIndex;

    

            for(int i=0; i<100; i++)

            {

                IWPParInterface par = Block.AppendParagraph();

                if (par != null)

                {

                    par.AppendText("This is Caption 1", header1);

                    Block.AppendParagraph();

                    par.AppendText("This is Caption 2", header2);

                    Block.AppendParagraph();

                    for (int j = 1; j < 30; j++) par.AppendText("some text ", body);

                    wpdllInt1.ReleaseInt(par);

                }

            }

            wpdllInt1.ReleaseInt(Block);

            Memo.ReformatAll();

 

 

Solution D) change the attributes of all characters in one paragraph

 

Here You can use

IWPAttrInterface Attr = Memo.CurrParAttr

 

This will change the character attributes of all the characters in one paragraph. You can add and remove properties, the other properties will not be changed. Please note, that with this property the character attributes are changed, not the attributes stored in the paragraph or a paragraph style. To change those use CurrPar.ParASet in IWPParInterface.

 

 

 

 

 

 

 

 

 

 

 

 


[font_attributes.htm]    Copyright © 2007 by WPCubed GmbH