The IWPAttrInterface to modify one character attribute in a paragraph.
Applies to
Declaration
function CharAttr(Index: Integer): IWPAttrInterface;
Description
This method returns an IWPAttrInterface reference which can be used to directly manipulate the attributes of one character in the paragraph. Please note that this interface is only valid until CharAttr is used the next time.
Example:
This code assigns the color red to all text which follows the comment signs "//". This example used the method EnumParagraphs which triggers the event OnEnumParOrStyle for all paragraphs in the text.
// Trigger event OnEnumParOrStyle
wpdllInt1.CurrMemo.EnumParagraphs(true,0);
// When done make sure the text is formatted and displayed
wpdllInt1.CurrMemo.ReformatAll(true,true);
This is the event handler for OnEnumParOrStyle:
private void wpdllInt1_OnEnumParOrStyle(
object Sender,
bool IsControlPar,
int StartPos,
int Count,
WPDynamic.IWPParInterface ParText,
WPDynamic.IWPAttrInterface ParAttr,
int EventParam,
ref bool Abort)
{
for ( int i = 0; i < ParText.CharCount; i++)
if (((char)ParText.GetChar(i)=='/')&&
((char)ParText.GetChar(i+1)=='/'))
{
while(i<ParText.CharCount)
{
ParText.CharAttr(i++).SetColor(
wpdllInt1.ToRGB(Color.Red));
}
}
}
Note: If you need to apply a certain attribute to more text it is better to calculate an character attribute index (using AttrHelper) and then use SetCharAttr to apply it.
Also see:
IWPParInterface.GetCharStyleAt
IWPParInterface.GetCharColorAt
IWPParInterface.GetCharBGColorAt
Category