This message contains graphics. If you do not see the graphics: Graphic Version.
 
Editing and Formatting Text From Code

Editing and Formatting Text From Code

There are various applications which require text to be edited from program code. Report generators assemble documents from various smaller files and database fields. Web shops create order confirmations and send them out as HTML or PDF. Using TX Text Control, anything that can be done using the mouse and clicking menu items, can also be done from program code. This newsletter discusses some of the techniques involved.

Selecting and Formatting Text

Text editing from code works similar to using the mouse and menus. To make a word bold, you would normally select it with the mouse, and then click on the Bold button. From code, you use TX Text Control's Selection.Bold property.

' Visual Basic TextControl1.Text = "TX Text Control" TextControl1.Selection.Start = 3 TextControl1.Selection.Length = 4 TextControl1.Selection.Bold = True
// C# textControl1.Text = "TX Text Control"; textControl1.Selection.Start = 3; textControl1.Selection.Length = 4; textControl1.Selection.Bold = true;

Find and Replace

As an alternative to specifying the start position and length of a word to be selected, TX Text Control's Find method can be used to locate it. In the following example, the font size of the word 'Text' is changed.

' Visual Basic TextControl1.Text = "TX Text Control" TextControl1.Find("Text") TextControl1.Selection.FontSize = 400
// C# textControl1.Text = "TX Text Control"; textControl1.Find("Text"); textControl1.Selection.FontSize = 400;

It is also possible to replace a piece of text once it has been selected. Note that there is no dedicated Replace method for this purpose, you simply use the Selection.Text property instead.

Appending and Inserting Text Files

The first thing required in order to insert a file into your document is to specify the location where it is to be inserted. This is done using the Selection.Load method can be used to insert a file, string or image. In the following example, first an RTF file is loaded, and then a HTML file is appended to its end.

' Visual Basic TextControl1.Load("..\TestFiles\Caption.rtf", _ TXTextControl.StreamType.RichTextFormat) TextControl1.Selection.Start = TextControl1.Text.Length TextControl1.Selection.Load("..\TestFiles\Net.htm", _ TXTextControl.StreamType.HTMLFormat)
// C# textControl1.Load ("..\\..\\TestFiles\\Caption.rtf", TXTextControl.StreamType.RichTextFormat); textControl1.Selection.Start = textControl1.Text.Length; textControl1.Selection.Load ("..\\..\\TestFiles\\Net.htm", TXTextControl.StreamType.HTMLFormat);

Moving to a Page, Line or Column

TX Text Control's InputPosition class tells you which page, line and column the current input position is at. It can also be used to move the input position to a different location.

The following example you shows how to create a Goto Page function. An instance of the InputPosition property.

' Visual Basic PageNo = InputBox("Page no.", "Go to page", "1") If PageNo > 0 And PageNo <= TextControl1.Pages Then Dim InputPosition As New TXTextControl.InputPosition(PageNo, 1, 0) TextControl1.InputPosition = InputPosition Else MsgBox("Page number outside valid range.", MsgBoxStyle.Exclamation) End If
// C# frmGotoPage GotoPage = new frmGotoPage(); GotoPage.ShowDialog(); if (GotoPage.PageNo > 0 && GotoPage.PageNo <= textControl1.Pages) { TXTextControl.InputPosition InputPosition = new TXTextControl.InputPosition(GotoPage.PageNo,1,0); textControl1.InputPosition = InputPosition; } else { MessageBox.Show("Page number outside valid range."); }

Note that the PageView. In all other modes, text is displayed continuously as a single page, so the property will always have a value of 1.


Best regards

The Newsletter Team

Text Control GmbH respects your online time and privacy. We only send this newsletter to TX Text Control customers and people who have signed up to receive it. However, if you would prefer not to receive future issues of the newsletter, you may unsubscribe at any time. If you received this newsletter forwarded from a colleague or friend, you may wish to subscribe directly.

Sent to: N/A.

Imprint | Unsubscribe | Subscribe

© 2003 Text Control GmbH. All Rights Reserved.