TextControl
TextControl is the word processing control of TX Text Control .NET for Windows Forms: the area of a form in which your users write, format and print documents. What it is, what you and your users do with it, how you put it on a form and which of its members you use first are described below, together with how it differs from ServerTextControl.
What TextControl Is
TextControl is a Windows Forms control with high-level text editing features. The class is TXTextControl.TextControl, derived from System.Windows.Forms.Control, so it behaves like any other control on a form: you dock it, anchor it, enable or disable it and handle its keyboard and mouse events. The reference documents the members TextControl adds; the inherited ones, such as Dock, Anchor and Text, are those of Control.
Everything a document consists of is available through properties and methods: text and paragraphs, tables, images, headers and footers, sections, fields, form fields, comments and tracked changes. Users edit these with the keyboard and the mouse, and your code reads and changes the same objects.
Unlike ServerTextControl, TextControl is created with the form and needs no call to Create. Both classes share the same programming interface for documents, so what you learn about one applies to the other.
What You Do With It
- Let users edit documents. Users type, select, copy and paste text, undo and redo changes, and format characters and paragraphs. Double-clicking selects a word, dragging moves selected text, and keyboard shortcuts such as Ctrl+Z and Ctrl+Y work as in other word processors.
- Format documents in code. The Selection property applies character and paragraph formatting to the selected text, and collections such as Tables, Images and HeadersAndFooters give you the elements of the document.
- Load and save documents as DOCX, RTF, HTML, PDF and other formats, either through the built-in Open and Save As dialog boxes or directly from a file, a stream, a byte array or a string. See Supported File Formats.
- Review and protect documents. Track changes, add comments, and make a document read-only except for the regions a user may edit.
- Print the document, with a print preview.
The ribbon, toolbars, rulers, status bar and sidebar that complete the editor are separate controls. Ribbon, Toolbars, Rulers, and Status Bar and Sidebar describe them.
Add It to a Form
After the setup is installed, the Visual Studio toolbox has a tab named TX Text Control 34.0. You draw the TextControl from that tab onto a form, and its smart tag adds a ribbon, rulers and a status bar and arranges them around the editor. Create Your First Windows Forms Application walks through these steps, and Visual Studio Designer Integration describes the smart tag.
How You Work With It
Choose How the Document Is Displayed
ViewMode sets how the document appears: as pages like a printed document (PageView), formatted to the page width without pages (Normal), filling the width of the control (FloatingText) or like a text box of fixed size (SimpleControl). Viewing, Zooming, and Navigation compares the modes.
PageSize and PageMargins are measured in the unit that PageUnit selects, by default 1/100 inch. ZoomFactor sets the zoom in percent.
Decide What Users May Change
EditMode controls editing: Edit allows everything, ReadAndSelect shows the text and lets users select it while DocumentPermissions decides what else they may do, and ReadOnly only shows the text; see Document Protection and Editable Regions. IsTrackChangesEnabled turns on the marking of changes.
Work With the Content
- The selection is the center of most editing code.
Selectionrefers to the part of the text that has the input focus, which is the main text, a header, a footer or a text frame. Setting its properties, such asBoldorFontSize, formats the selected text. - The collections
Tables,Images, ApplicationFields, Paragraphs and TrackedChanges also refer to the text part with the input focus. Sections and FormFields hold elements of the whole document. - The input position is where typed text appears. InputPosition gets or sets it.
React to Changes
Events tell your code what happens in the editor. Changed occurs when the contents change, for example to mark a document as modified. InputPositionChanged occurs when the input position moves, for example to update your own toolbar. DocumentLoaded occurs after a document has been loaded.
Example
Load and Save Documents in Getting Started builds New, Open, Save and Save As commands around a TextControl: they use the built-in dialog boxes, track changes to the document with the Changed event and load and save files and byte arrays without a dialog box.
Key Members
| Member | Purpose |
|---|---|
| Load | Loads a document and replaces the complete contents, or opens the Open dialog box. |
| Save | Saves the complete document, or opens the Save As dialog box. |
| Append | Adds a document to the end of the existing one. |
| Selection | The current selection, used to insert text and to apply character and paragraph formatting. |
| ViewMode | How the document is displayed. |
| EditMode | Whether the text can be edited, only selected or only read. |
| Tables, Images, HeadersAndFooters | The tables, images, headers and footers of the document. |
| Comments, TrackedChanges | The comments and the tracked changes. |
| Undo, Redo | Undo and redo the last action. AllowUndo turns the undo history off, which saves time and memory when code builds a large document. |
| Copy, Cut, Paste | Clipboard operations. |
| Find, Replace | Search the text in code, or open the built-in Find and Replace dialog boxes. |
| Print, PrintPreview | Print the document or show a preview. |
| Changed, InputPositionChanged | Occur when the contents change and when the input position moves. |
The TextControl reference lists all members.
Next Steps
- Create Your First Windows Forms Application: put a
TextControlon a form and run it. - Ribbon, Toolbars, Rulers, and Status Bar: the controls that complete the editor.
- Document Editor: each editing feature of
TextControlin detail. - ServerTextControl: the same document engine without a user interface.