TX Text Control .NET for Windows Forms

Migrating From ActiveX

Topic

Applications written with TX Text Control ActiveX in Visual Basic 6 or another COM environment move to .NET with TX Text Control .NET for Windows Forms. Most members have a .NET counterpart, but the programming interface is organized differently: the long list of properties, methods and events of the ActiveX control is spread over classes such as Selection, ParagraphFormat and a collection for each kind of document object. The tables below name the .NET replacement of every ActiveX member, grouped by category, followed by the tool bars and the members that .NET doesn't need.

How the .NET Interface Differs

Most ActiveX members map to a .NET member with a similar name. The patterns below explain the rest:

  • Formatting belongs to classes. Character formatting of the current selection is set through Selection, so FontBold becomes Selection.Bold. Paragraph attributes such as Alignment and the indents are properties of ParagraphFormat, and page, column and section settings are properties of PageMargins and SectionFormat. Because a class applies its attributes in one step, LockWindowUpdate is no longer needed.
  • Document elements are objects in collections. Images, text frames, text fields, tables, sections, headers and footers and editable regions each have a class and a collection. The ActiveX ...Insert and ...Delete methods become Add and Remove of the collection, the ...AtInputPos properties become GetItem, and the ...Next methods become a foreach loop. Properties that selected the "current" object, such as FieldCurrent or ObjectCurrent, disappear: you set the properties of the object itself.
  • Events are named in the past tense. CharFormatChange becomes CharFormatChanged, ParagraphFormatChange becomes ParagraphFormatChanged, and PosChange becomes InputPositionChanged.
  • Standard control members come from Windows Forms. TextControl, ButtonBar, RulerBar and StatusBar derive from the Windows Forms class Control. Members such as Click, KeyDown, Font, Enabled and Handle are inherited from it, so the tables show them in code without a link to the TX Text Control reference.
  • Errors are exceptions. The ActiveX Error event has no counterpart: .NET methods throw exceptions, as Exceptions and Error Handling describes.
  • Server-side automation uses ServerTextControl. Where an ActiveX application called EnableAutomationServer, a .NET application uses ServerTextControl, described in Using ServerTextControl in Desktop Applications.

Port the Code

Start with a Windows Forms project that has a TextControl on its form, as Create Your First Windows Forms Application creates it. Then rewrite each ActiveX call with the tables below. This handler in Form1.cs shows the three most common changes, with the ActiveX code in the comments:

using TXTextControl;

private void PortedCode()
{
    // ActiveX: TXTextControl1.FontBold = True
    textControl1.Selection.Bold = true;

    // ActiveX: TXTextControl1.IndentL = 567
    textControl1.Selection.ParagraphFormat.LeftIndent = 567;

    // ActiveX: FieldNext, FieldCurrent and FieldText in a loop
    foreach (TextField field in textControl1.TextFields)
    {
        System.Diagnostics.Debug.WriteLine(field.Text);
    }
}

The code works as follows:

The pages of the Document Editor section explain each area of the .NET interface in detail, such as Text and Paragraph Formatting, Tables and Table Formulas and Fields, Hyperlinks, and Bookmarks.

Map the Members by Category

Each table lists the members of the ActiveX control TXTextControl in one category, linked to the ActiveX reference, and the .NET classes, properties, methods or events that replace them. Members with no .NET counterpart are listed in Members Without a Counterpart.

Character Formatting

Paragraph Formatting

Bullets and Numbered Lists

Headers and Footers

Text Frames

Page and Document Settings

Stylesheets

ActiveX.NET
Style objectFormattingStyle, InlineStyle, ParagraphStyle
StyleChanged eventTextControl.InputFormattingStyleChanged
StyleCurrent propertySelection.FormattingStyle
StyleDialog methodTextControl.FormattingStylesDialog
StyleListChanged eventTextControl.FormattingStyleListChanged
Styles collectionInlineStyleCollection, ParagraphStyleCollection
Styles propertyTextControl.InlineStyles, TextControl.ParagraphStyles
Style.Alignment propertyParagraphFormat.Alignment
Style.Apply methodFormattingStyle.Apply
Style.Baseline propertyFormattingStyle.Baseline
Style.BaselineType propertyFormattingStyle.Baseline
Style.BulletAttribute propertyListFormat.BulletCharacter, ListFormat.BulletSize
Style.FontBold propertyFormattingStyle.Bold
Style.FontItalic propertyFormattingStyle.Italic
Style.FontName propertyFormattingStyle.FontName
Style.FontSize propertyFormattingStyle.FontSize
Style.FontStrikethru propertyFormattingStyle.Strikeout
Style.FontUnderline propertyFormattingStyle.Underline
Style.ForeColor propertyFormattingStyle.ForeColor
Style.FrameDistance propertyParagraphFormat.FrameDistance
Style.FrameLineWidth propertyParagraphFormat.FrameLineWidth
Style.FrameStyle propertyParagraphFormat.FrameStyle
Style.IndentB propertyParagraphFormat.BottomDistance
Style.IndentFL propertyParagraphFormat.HangingIndent (a negative value indents the first line)
Style.IndentL propertyParagraphFormat.LeftIndent
Style.IndentR propertyParagraphFormat.RightIndent
Style.IndentT propertyParagraphFormat.TopDistance
Style.KeepLinesTogether propertyParagraphFormat.KeepLinesTogether
Style.KeepWithNext propertyParagraphFormat.KeepWithNext
Style.LineSpacing propertyParagraphFormat.LineSpacing
Style.LineSpacingT propertyParagraphFormat.AbsoluteLineSpacing
Style.ListType propertyListFormat.Type
Style.NextParaStyle propertyParagraphStyle.FollowingStyle
Style.NumberingAttribute propertyListFormat.NumberFormat
Style.PageBreakBefore propertyParagraphFormat.PageBreakBefore
Style.StyleName propertyFormattingStyle.Name
Style.StyleType propertyFormattingStyle, the base class of InlineStyle and ParagraphStyle
Style.TabPos propertyParagraphFormat.TabPositions
Style.TabType propertyParagraphFormat.TabTypes
Style.TextBkColor propertyFormattingStyle.TextBackColor
Style.WidowOrphanLines propertyParagraphFormat.WidowOrphanLines
Styles collectionInlineStyle, ParagraphStyle
Styles.Count propertyFormattingStyleCollection.Count
Styles.Item methodParagraphStyleCollection.GetItem

Tables

ActiveX.NET
TableAtInputPos propertyTableCollection.GetItem
TableAttrDialog methodTextControl.TableFormatDialog
TableCanDeleteColumn propertyTableColumnCollection.CanRemove
TableCanDeleteLines propertyTableRowCollection.CanRemove
TableCanInsert propertyTableCollection.CanAdd
TableCanInsertColumn propertyTableColumnCollection.CanAdd
TableCanInsertLines propertyTableRowCollection.CanAdd
TableCellAttribute propertythe properties of TableCellFormat, TableCell.CellFormat, TableRow.CellFormat, TableColumn.CellFormat, TableCell.Width, TableCell.Position
TableCellLength propertyTableCell.Length
TableCellStart propertyTableCell.Start
TableCellText propertyTableCell.Text
TableColAtInputPos propertyTableColumnCollection.GetItem
TableColumns propertyTablePartCollection.Count
TableCreated eventTextControl.TableCreated
TableDeleteColumn methodTableColumnCollection.Remove
TableDeleted eventTextControl.TableDeleted
TableDeleteLines methodTableRowCollection.Remove
TableFormatChanged eventTextControl.TableFormatChanged
TableGridLines propertyTableCollection.GridLines
TableInsert methodTableCollection.Add
TableInsertColumn methodTableColumnCollection.Add
TableInsertLines methodTableRowCollection.Add
TableNext methodTableCollection (enumerate it with foreach)
TableRowAtInputPos propertyTableRowCollection.GetItem
TableRows propertyTablePartCollection.Count
TableCanSplit propertyTable.CanSplit
TableGetOuter methodTable.OuterTable
TableGetOuterMost methodTable.OuterMostTable
TableNestedLevel propertyTable.NestedLevel
TableSplit methodTable.Split

Zooming

Loading, Saving and Database Support

Images and OLE Objects

Hypertext Links

Clipboard Operations

Undo

Printing

ActiveX.NET
PrintColors propertyTextControl.Print, PrintDocument.DefaultPageSettings.Color
PrintDevice propertyTextControl.Print, PrintDocument.PrinterSettings.PrinterName
PrintDoc methodTextControl.Print
PrintPage methodTextControl.Print

Search and Replace

Columns

Sections

Control Styles and Mode Settings

Line Operations

Text Controls Without a Built-In Scroll Interface

Selections and Character Input

ActiveX.NET
CaretWidth propertyTextControl.CaretWidth
Click eventTextControl.Click
CurrentInputPosition propertyInputPosition, TextControl.InputPosition
DblClick eventTextControl.DoubleClick
FormatSelection propertySelection, TextControl.Selection
InputPosFromPoint methodInputPosition, TextControl.InputPosition, TextCharCollection.GetItem
KeyDown eventTextControl.KeyDown
KeyPress eventTextControl.KeyPress
KeyUp eventTextControl.KeyUp
MouseDown eventTextControl.MouseDown
MouseMove eventTextControl.MouseMove
MouseUp eventTextControl.MouseUp
MousePointer propertyTextControl.Cursor
ParagraphChange eventInputParagraphChanged
PosChange eventInputPositionChanged
RTFSelText propertySelection.Load, Selection.Save
SelLength propertySelection.Length
SelStart propertySelection.Start
SelText propertySelection.Text
TabKey propertyTextControl.AcceptsTab

Marked Text Fields

Integrated Dialog Boxes

Handling XML Documents

Tool Bar Support

Restricted Document Access

Miscellaneous

ActiveX.NET
hWnd propertyTextControl.Handle
Refresh methodTextControl.Refresh
ResetContents methodTextControl.ResetContents

Port the Tool Bars

The ActiveX tool bars TXButtonBar, TXRulerBar and TXStatusBar have the .NET counterparts ButtonBar, RulerBar and StatusBar. An ActiveX application connected them through window handles such as ButtonBarHandle. In .NET, you assign the bar object to the properties ButtonBar, RulerBar, VerticalRulerBar and StatusBar of the TextControl, in the Properties window or in code, and the ConnectTools event is no longer needed.

A Windows Forms form in the designer with a button bar, a horizontal and a vertical ruler, a TextControl and a status bar.

Add Rulers, Toolbars, and a Status Bar builds this layout step by step. Instead of the button bar, a Windows Forms application can also use the ribbon, described in Built-in Ribbon Tabs.

The members of the three bars map as follows.

Button Bar

ActiveX.NET
Appearance propertyButtonBar.BorderStyle
BorderStyle propertyButtonBar.BorderStyle
Enabled propertyButtonBar.Enabled
hWnd propertyButtonBar.Handle
MouseDown eventButtonBar.MouseDown
MouseMove eventButtonBar.MouseMove
MouseUp eventButtonBar.MouseUp
The Pos properties, such as PosFontBoldButtonBar.ButtonOffsets, ButtonBar.ButtonPositions, ButtonBar.ButtonSeparators
Style propertyButtonBar.ButtonStyle

Ruler Bar

ActiveX.NET
BorderStyle propertyRulerBar.BorderStyle
Enabled propertyRulerBar.Enabled
hWnd propertyRulerBar.Handle
MouseDown eventRulerBar.MouseDown
MouseMove eventRulerBar.MouseMove
MouseUp eventRulerBar.MouseUp
ScaleUnits propertyRulerBar.ScaleUnit

Status Bar

ActiveX.NET
BorderStyle propertyStatusBar.BorderStyle
Enabled propertyStatusBar.Enabled
Font propertyStatusBar.Font
FontBold propertyStatusBar.Font
FontItalic propertyStatusBar.Font
FontName propertyStatusBar.Font
FontSize propertyStatusBar.Font
FontStrikethru propertyStatusBar.Font
FontUnderline propertyStatusBar.Font
hWnd propertyStatusBar.Handle
MouseDown eventStatusBar.MouseDown
MouseMove eventStatusBar.MouseMove
MouseUp eventStatusBar.MouseUp
Text propertyStatusBar.Text
TextColumn propertyStatusBar.ColumnText
TextLine propertyStatusBar.LineText
TextPage propertyStatusBar.PageText

Members Without a Counterpart

No Longer Needed

These ActiveX members have no .NET counterpart because the .NET interface solves their task another way:

ActiveXWhat replaces it
TabCurrent propertyNothing: TabPositions and TabTypes hold all tabs of a paragraph as arrays
HeaderFooterSelect methodThe properties of each HeaderFooter object
ObjectCurrent propertyThe properties of each Image object
FieldCurrent propertyThe properties of each TextField object
SectionCurrent propertyThe SectionCollection of TextControl.Sections
LockWindowUpdate propertyNothing: the formatting classes apply their attributes in one step
ConnectTools eventNothing: the bars connect without a window handle, see Port the Tool Bars
Error eventExceptions, see Exceptions and Error Handling
Language property of TXTextControl, TXButtonBar, TXRulerBar and TXStatusBarNothing: the language of the user interface follows the system, see Localization and Resource Kit
ResourceFile property of TXTextControl, TXButtonBar, TXRulerBar and TXStatusBarSatellite assemblies, see Localization and Resource Kit
PageMode property of TXStatusBarNothing: the status bar follows TextControl.ViewMode

Not Available in .NET

These ActiveX members have no replacement in TX Text Control .NET for Windows Forms:

Next Steps