This important interface is used to update the character attributes and paragraph attributes.
The interface is published by property CurrAttr, TextAttr and CurrSelAttr. CurrAttr changes the current writing mode, CurrSelAttr the selected text and TextAttr provides automatically the CurrAttr or CurrSelAttr if text is selected.
You can use TextAttr to fill your own toolbar with life, in case you do not want to use the inbuilt toolbar to change the attributes of the text. You can also use it to implement hotkeys, for example toggle 'bold' when pressing Ctrl+B.
The default text attributes can be changed in Memo.DefaultAttr. (If a function of TextAttr returns FALSE this means the default attribute is used for this property.)
The instance "AttrHelper" can be used to calculate CharAttrIndex values to be used with TextCursor.InputString.
A different instance is published as property CurrParAttr (Memo.CurrParAttr or RTFDataBlock.CurrParAttr). Here any change will affect all characters in this paragraph. Please note that it will not change the properties stored by the paragraph itself, but the properties used by the individual characters - in the attribute cache.
If you need to change the character attributes stored in the paragraph object you can use the method CurrPar.ParASet.
CurrStyleAttr is used to change the character attributes defined by a style. You can use SelectStyle to create a new paragraph style or select an existing style to be modified. To apply a style a style to a paragraph, you can use the property StyleName.
The interface IWPAttrInterface has several methods to read and write properties.
The basic methods which can access all attributes are AttrGet, AttrDel and AttrSet. These methods expect the property ID (WPAT...) - Please see the list of the available WPAT codes. If the AttrGet function returns the value false, the value has not been defined. This means the inherited or the default value will be used for this property. This three basic functions will modify the character attributes for IDs <=16, for IDs >16 the current paragraph / selected paragraphs will be modified. You can use Memo.TextAttr.AttrSET((int)WPAT.IndentLeft, 360) to change the indent of the current paragraph or all selected paragraphs, in case text was selected.
The other methods only affect the character attributes. For other changes on paragraphs or styles use IWPParInterface.
The property CharAttrIndex represents the writing mode as index into the attribute cache. The value can be used with TextCursor.InputText("some text", x). You can store it into an integer variable if you need to temporarily change the writing mode. When you are done simply assign the value and you can use the previous writing mode. Please note that clearing the text makes the index values invalid!
Please note: The methods to read a property "Get...." all return a boolean value. If this value is FALSE, this means the property is not used, the property uses the default value.
With .NET use the API ColorTranslator.FromWin32(rgb) to convert a RGB value into the Color type.
You can use ColorToRGB to convert a Color type into RGB.
This C# example code creates text to show the possible underline modes.
string cnames = new string
, "WPUND_curlyunderline" };
IWPMemo Memo = WPDLLInt1.Memo;
IWPAttrInterface CurrAttr = Memo.CurrAttr;
IWPTextCursor TextCursor = Memo.TextCursor;
//150% Line Height
int m = 1;
foreach (string s in cnames)
TextCursor.InputText(" = ");