Text

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

To enter text using code it is easiest to use

IWPTextCursor.InputText or TextCursor.InputString.

 

The later allows it to specify a CharAttr index value (see Introduction) which can be calculated by "AttrHelper".

 

// We need this interfaces for text creation

IWPMemo Memo = WPDLLInt1.Memo;

IWPTextCursor TextCursor = Memo.TextCursor;

IWPAttrInterface AttrHelper = WPDLLInt1.AttrHelper;

 

// Calculate a character style index value

AttrHelper.Clear();

AttrHelper.SetFontface("Times New Roman");

AttrHelper.SetFontSize(11);

AttrHelper.IncludeStyles(2); // Italic

int mycharattr = AttrHelper.CharAttrIndex;

 

// and insert some text

TextCursor.InputString("Hello World", mycharattr);

 

You can also load a formatted string (RTF or HTML) at cursor position. This can be done using IWPTextCursor.InputHTML or the load methods with the "insert" flag set to true: Memo.LoadFromFile, LoadFromStream, LoadFromString, LoadFromVar.

 

If you want to change the text in the current paragraph it is also possible to access it directly using the Memo.CurrPar interface. This interface contains methods such as IWPParInterface.AppendText and IWPParInterface.SetText. Accessing the IWPParInterface can be very useful if you want to change or evaluate the text without moving the cursor position. To do so use the method Memo.EnumParagraphs to process all paragraphs in the text. Alternatively You can also "move" CurrPar by using its "Low level move Methods".

 

To move the cursor, the insertion mark, use CPPosition or the other "CP" properties, or methods such as IWPTextCursor.CPMoveBack and IWPTextCursor.CPMoveNext.

 

There are also methods to find text (IWPTextCursor.FindText), fields (IWPTextCursor.MoveToField), bookmarks (IWPTextCursor.MoveToBookmark) and tables (IWPTextCursor.MoveToTable). The method IWPTextCursor.MovePosition can be used to skip words or move to the start or end of a line.

 

To temporarily store the cursor position use the "marker API". The markers are managed in a way, that if you use InputString to insert text before a marker, the marker position will be automatically incremented. See IWPTextCursor.MarkerCollect, IWPTextCursor.MarkerDrop and IWPTextCursor.MarkerGoto.


[text.htm]    Copyright © 2007 by WPCubed GmbH