
Text Control manages one collection which contains all images and one collection which contains all text frames of a document. The following describes the collection of images, the collection of text frames works in the same way.
The image collection can be used to add or to remove images. There are several versions of Add methods for the three ways of inserting images.
The following two methods insert an image inline:
[C#]
public bool Add();
public bool Add(Image image, int textPosition);
[Visual Basic]
Public Function Add() As Boolean
Public Function Add(ByVal image As Image, ByVal textPosition As Integer) As Boolean
The first version has no parameters and opens a File Open dialog box that provides all image formats TX Text Control supports. The user can select an image, close the dialog box and the image is added to the collection and automatically inserted in the document at the current input position. The second method inserts the image at the specified text position. The second method opens a file open dialog box only, if the Image.FileName and/or the Image.FilterIndex property of the specified Image object are not initialized.
The following two methods insert an image anchored to a paragraph:
[C#]
public bool Add(Image image, HorizontalAlignment alignment, int textPosition, ImageInsertionMode insertionMode);
public bool Add(Image image, Point location, int textPosition, ImageInsertionMode insertionMode);
[Visual Basic]
Public Function Add(ByVal image As Image, ByVal alignment As HorizontalAlignment, ByVal textPosition As Integer, _
ByVal insertionMode As ImageInsertionMode) As Boolean
Public Function Add(ByVal image As Image, ByVal location As Point, ByVal textPosition As Integer, _
ByVal insertionMode As ImageInsertionMode) As Boolean
The text position can be any position in the paragraph. If -1 is specified, the image is anchored to the paragraph containing the current text input position. The location of the image relative to the paragraph is determined through a horizontal alignment or through a horizontal and a vertical offset. The position and extension of a paragraph is determined through its left and its right paragraph indent. The insertionMode parameter determines whether the text flows around or is continued below the image. A file open dialog box is opened only, if the Image.FileName and/or Image.FilterIndex property of the specified Image object are not initialized.The Image.Alignment property is only available for images anchored to a paragraph, for inline images and fixed positioned images a horizontal alignment is not defined.
The following two methods insert an image at a fixed geometric position in the document:
[C#]
public bool Add(Image image, int page, Point location, ImageInsertionMode insertionMode);
public bool Add(Image image, Point location, ImageInsertionMode insertionMode);
[Visual Basic]
Public Function Add(ByVal image As Image, ByVal page As Integer, ByVal location As Point, _
ByVal insertionMode As ImageInsertionMode) As Boolean
Public Function Add(ByVal image As Image, ByVal location As Point, _
ByVal insertionMode As ImageInsertionMode) As Boolean
The position is either a position on a certain page or a position relative to the top-left corner of the complete document. The horizontal value is relative to the left edge of all pages and the vertical value is relative to the top of the document including the gap above the first page. Regardless of which method has been used to insert the image the Image.Location property returns the location relative to the complete document. The insertionMode parameter determines whether the text flows around or is continued below the image. A file open dialog box is opened only, if the Image.FileName and/or Image.FilterIndex property of the specified Image object are not initialized.
The following code shows an example for inserting an image anchored to the fifth paragraph of a document:
[C#]
Paragraph p = textControl1.Paragraphs[5];
textControl1.Images.Add(new Image(), HorizontalAlignment.Left, p.Start-1, ImageInsertionMode.DisplaceText);
[Visual Basic]
Dim p As Paragraph = TextControl1.Paragraphs.Item(5)
TextControl1.Images.Add(New Image(), HorizontalAlignment.Left, p.Start - 1, ImageInsertionMode.DisplaceText)