IWPTextCursor TextCursor

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

The cursor interface is used to create text under program control and to position the cursor.


Create some text and display it:


 IWPTextCursor TextCursor;

 TextCursor = WPDLLInt1.Memo.TextCursor;

 TextCursor.InputText("Hello World\nand a new line ....");



Insert a Picture:


If you want to insert a picture which is currently displayed in a .NET PictureBox you need to use the class WPDynamic.Image2Picture.



         new WPDynamic.Image2Picture(pictureBox1.Image),0,0);


This are the methods to insert images. The result value is 0 if no image was insered:


a) int InputImage(string filename, int Mode);


The image is loaded from a file. The following formats are supported: BMP, WMF, EMF, JPEG, PNG.


If bit 1 was set in parameter 'mode' the image will not be embedded, only a link to the file will be stored.


b) int InputPicture(IUnknown Picture, int Width, int Height);


This method inserts a picture defined by either a IPicture interface (common in VB6) or, under .NET, the interface IWPPicture which is provided by the utility class Image2Picture. IWPPicture does, unlike IPicture, also handle PNG and JPEG data.


c) int InputPictureStream(IUnknown Stream, string FileExt, int Width, int Height);


This method inserts image data stored in a stream. The property FileExt tells the method the format of the data for example "BMP".


The parameter Stream can be either an IStream or IWPStream interface. The latter is published by the helper class Stream2WPStream which is implemented in the C# wrapper.


In this example we create a file stream from an image file and insert it.


 IWPTextCursor TextCursor = WPDLLInt1.Memo.TextCursor;

 FileStream stream = new FileStream(



                         new WPDynamic.Stream2WPStream(stream),"jpg",




Width and Height are always measured in twips (= 1/1440 inch). If 0, the content width and height will be used.


Insert a Table


To create a table there are four options.


a) use InputTable, InputRowStart, [InputCell....] InputRowEnd

b) use AddTable and the event OnCreateNewCell which is called for each created cell

c) use AddTable to create the first row and then append to that table using CPMoveNextRow(true)

d) use low level ParInterface methods.


Please see the table support category.


Which option is better depends on the problem you need to solve. Option requires less coding. But it requires more abstraction and also that the data which should be inserted is available in event handler as well. The option a) is good if you do not know in advance the count of rows you need to create. It also makes it possible to create tables with a different column count in each row. The option c) mimics the way somebody would create a table "by hand". d) is a versatile approach which directly works with the paragraph objects. It allows the creation of a table without moving the cursor position.

[iwptextcursortextcursor.htm]    Copyright © 2007 by WPCubed GmbH