TX Text Control .NET for Windows Forms

Selection Class

Class
Namespace
TXTextControl
Package
TXTextControl.TextControl.WinForms.SDK from the private NuGet feed or Text Control Offline Packages
Assembly
TXTextControl.dll
Install
dotnet add package TXTextControl.TextControl.WinForms.SDK .NET 8 and later. For .NET Framework, reference TXTextControl.dll from the setup.

Description

The Selection class describes and handles the attributes of a text selection. Each of the properties of this class returns the property's default value if the selection does not contain a common value. In this case the IsCommonValueSelected method returns false.

Syntax

public class Selection

Examples

The following example shows how to select and format a piece of text.

textControl1.Text = "TX Text Control";

TXTextControl.Selection mySel = new TXTextControl.Selection(3, 4);
mySel.Bold = true;
mySel.Italic = true;

textControl1.Selection = mySel;

The following example creates a reusable selection format and applies it to the current report heading.

textControl.Text = "Quarterly results";
textControl.Select(0, textControl.Text.Length);
Selection selection = new() { Bold = true, FontSize = 280 };
textControl.Selection = selection;

Members

Constructors

ConstructorDescription
SelectionCreates a new instance of the Selection class.

Properties

PropertyDescription
AutoBaselineGets or sets values specifying wheather the selected text is automatically sub- or superscripted. When using automatic sub- and superscript the font is scaled and moved above or below the baseline with values defined through the font itself. Automatic sub- and superscript can be combined with a user-defined baseline which can be set with the Baseline property.
BaselineGets or sets the baseline alignment, in twips, of the selected text. Positive values moves the baseline to superscript, negative values move the baseline to subscript.
BoldGets or sets the bold attribute of the selected text.
CapitalsGets or sets values specifying wheather the lowercase letters of the selected text are displayed with capital letters. Lowercase letters are displayed either with capital letters of the same size or with capital letters which have a smaller size. The smaller size is either the size of the lowercase 'x' (petite caps) or the size of the lowercase 'x' + 10% (small caps).
CharacterScalingGets or sets a character scaling, in percent of the average character width, of the selected text.
CharacterSpacingGets or sets a character spacing value, in twips, of the selected text. This value is added to each character. When it is negative, character spacing is reduced, otherwise it is extended.
CultureGets or sets the culture of the selected text.
FontNameGets or sets the font of the selected text.
FontSizeGets or sets the font's size, in twips, of the selected text.
ForeColorReturns or sets the color used to display the selected text.
FormattingStyleGets or sets the formatting style of the selected text.
ItalicGets or sets the italic attribute of the selected text.
LengthReturns or sets the number of characters selected. If this property is zero, no text is selected and the Start property determines the current text input position. To select parts of a table, the Table.Select, TableRow.Select, TableColumn.Select and TableCell.Select methods must be used.
ListFormatGets or sets a bulleted or numbered list and/or its formatting attributes for the selected text. The property's value is an object of the type ListFormat.
ParagraphFormatGets or sets the formatting attributes of the selected paragraphs. The property's value is an object of the type ParagraphFormat.
SectionFormatGets or sets page settings such as margins, size and orientation for the selected text. The property's value is an object of the type SectionFormat.
StartGets or sets the starting point of selected text. The first possible position is 0. If the starting point of a selection is set to a new value, the selection's current length remains the same. To set a new starting point and a length simultaneously, use either the TextControl.Select method or create a new Selection object. To select parts of a table, use the Table.Select, TableRow.Select, TableColumn.Select and TableCell.Select methods.
StrikeoutGets or sets the strikeout attribute of the selected text.
TextGets or sets a string containing the currently selected text.
TextBackColorGets or sets the background color for selected text.
UnderlineGets or sets underlining styles for the selected text.

Methods

MethodDescription
ChangeCapitalizationChanges the capitalization of all selected characters depending on the settings parameter.
ChangeDirectionChanges the writing direction of all selected paragraphs. When the direction of a paragraph is changed, this paragraph's alignment is toggled from left to right or from right to left. The alignment of centered and justified paragraphs is not changed. Left and right tabulators are also toggled.
DecreaseIndentDecreases the left indent of all paragraphs contained in the current text selection. If no text is selected, this method decreases the left indent at the text input position. Left indent positions are defined through the paragraphs' tab positions and the indents of the paragraphs in front and behind the paragraph with the text input position.
GrowFontIncreases the font size of each font contained in the current text selection. If no text is selected, this method increases the font size at the text input position. The font sizes used with this method are the same as shown through the ButtonBar or the built-in font dialog.
IncreaseIndentIncreases the left indent of all paragraphs contained in the current text selection. If no text is selected, this method increases the left indent at the text input position. left indent positions are defined through the paragraphs' tab positions and the indents of the paragraphs in front and behind the paragraph with the text input position.
IsCommonValueSelectedInforms about whether a certain attribute has the same value for the complete selection.
LoadExchanges the currently selected text with text in a certain format.
RemoveFormattingResets all character based formatting attributes of the selected text to its default values. If nothing or more than one paragraph is selected, all paragraph based formatting attributes are also reset.
RemoveInlineStylesRemoves all character based styles of the selected text so that all attributes are reset to the attributes of the paragraph style.
SaveSaves the selected text of a document with the specified format.
ShrinkFontDecreases the font size of each font contained in the current text selection. If no text is selected, this method decreases the font size at the text input position. The font sizes used with this method are the same as shown through the ButtonBar or the built-in font dialog.

Enumerations

EnumerationDescription
AttributeDetermines a certain attribute. This enumeration is used with the IsCommonValueSelected method.
DialogResultSpecifies identifiers to indicate the return value of a dialog box.