TX Text Control .NET for Windows Forms

Alignment Property

Property
Namespace
TXTextControl
Package
TXTextControl.TextControl.WinForms.SDK as TXTextControl.dll from the private NuGet feed or Text Control Offline Packages

Description

Gets or sets the horizontal text alignment.

Syntax

public HorizontalAlignment Alignment { get; set; }

Members

ValueDescription
LeftText is left aligned.
RightText is right aligned.
CenterText is centered.
JustifyText is justified.

Examples

The following example applies paragraph layout to selected report text by using ParagraphFormat.Alignment.

textControl.Text = "First item\nSecond item\nThird item";
textControl.Select(0, textControl.Text.Length);
ParagraphFormat paragraphFormat = textControl.Selection.ParagraphFormat;

paragraphFormat.Alignment = TXTextControl.HorizontalAlignment.Center;
Console.WriteLine($"Alignment used by Paragraph Format: {paragraphFormat.Alignment}");

textControl.Selection.ParagraphFormat = paragraphFormat;

Remarks

The property's default value is HorizontalAlignment.Left.

The property returns its default value when the text selection contains multiple paragraphs with mixed alignment. The Selection.IsCommonValueSelected method can be used to check for mixed attributes.

Further Reading

  • Grouping Undo Steps with TX Text Control –
  • Manipulating the Selection Object –