Back to Devexpress

TextOptions.HAlignment Property

windowsforms-devexpress-dot-utils-dot-textoptions-6ce2b199.md

latest10.2 KB
Original Source

TextOptions.HAlignment Property

Gets or sets the horizontal alignment of text.

Namespace : DevExpress.Utils

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[DefaultValue(HorzAlignment.Default)]
[XtraSerializableProperty]
public virtual HorzAlignment HAlignment { get; set; }
vb
<DefaultValue(HorzAlignment.Default)>
<XtraSerializableProperty>
Public Overridable Property HAlignment As HorzAlignment

Property Value

TypeDefaultDescription
HorzAlignmentDefault

A HorzAlignment value that specifies the text horizontal alignment.

|

Available values:

NameDescription
Default

Places an object or text at the default position, which is determined by a control.

| | Near |

Places an object/text at a near position.

| | Center |

Centers an object or text within a region.

| | Far |

Places an object/text at a far position.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to HAlignment
AppearanceObject

.TextOptions .HAlignment

| | TextOptions |

.DefaultOptions .HAlignment

| | TextOptions |

.DefaultOptionsCenteredWithEllipsis .HAlignment

| | TextOptions |

.DefaultOptionsMultiLine .HAlignment

| | TextOptions |

.DefaultOptionsNoWrap .HAlignment

| | TextOptions |

.DefaultOptionsNoWrapEx .HAlignment

|

Remarks

When an AppearanceObject’s style setting (for example, BackColor , ForeColor , Font and TextOptions.HAlignment ) is set to a non-default value, the corresponding Options.Use… option (for instance, Options.UseBackColor , Options.UseForeColor , Options.UseFont and Options.UseTextOptions ) is automatically set to true in the following cases:

  • The AppearanceObject belongs to a control/component (or its element), and this control/component has been completely loaded (see the control’s IsLoading property to check the load status);
  • The AppearanceObject belongs to a grid column/band or tree list column/band, and the column/band belongs to a grid/tree list control;
  • The AppearanceObject is standalone, that is, it does not belong to any control or component.

In other cases, the Options.Use… options are not automatically enabled. You may need to enable these options manually for the style settings to be in effect.

Specific Notes

  • Use either the HAlignment property or the align HTML attribute to specify the horizontal alignment. These settings are incompatible and cannot be used together.
  • If the editor is used in a data-aware control, use the column’s AppearanceCell.TextOptions.HAlignment property to specify the horizontal alignment when the editor is inactive:

The following code snippets (auto-collected from DevExpress Examples) contain references to the HAlignment property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-mvvm-best-practices/CS/EventToCommandBehaviorParametersConverters/PassingParametersToCommandsUserControl.cs#L26

csharp
label.AutoSizeMode = LabelAutoSizeMode.None;
label.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
label.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;

winforms-docking-display-custom-header-buttons/CS/CustomHeaderButtonsExample/Form1.cs#L33

csharp
void panelContainer1_CustomButtonChecked(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e) {
    if (e.Button == panelContainer1.CustomHeaderButtons[4]) (panelContainer1.ActiveChild.ControlContainer.Controls[0] as MemoEdit).Properties.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
    if (e.Button == panelContainer1.CustomHeaderButtons[3]) (panelContainer1.ActiveChild.ControlContainer.Controls[0] as MemoEdit).Properties.Appearance.TextOptions.HAlignment = HorzAlignment.Center;

XAF-how-to-add-an-unbound-column-to-gridlisteditor-to-execute-a-custom-action-for-a-record/CS/EFCore/ButtonInListEF/ButtonInListEF.Win/Controllers/SimpleBusinessActionGridListViewController.cs#L59

csharp
buttonColumn.Caption = ButtonColumnCaption;
buttonColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
buttonColumn.VisibleIndex = 0;

winforms-grid-copy-cells-in-biff8-format-using-excel-export-api/CS/gridCopyToClipboardExample/CopyToClipboardHelper.cs#L75

csharp
VerticalAlignment = ConvertAlignment(appearance.TextOptions.VAlignment),
    HorizontalAlignment = ConvertAlignment(appearance.TextOptions.HAlignment)
};

winforms-xtraform-center-caption/CS/WindowsApplication1/Custom Form Painter/CustomFormPainter.cs#L36

csharp
appearance.TextOptions.Trimming = Trimming.EllipsisCharacter;
appearance.TextOptions.HAlignment = CaptionAlignment;
if (AllowHtmlDraw) {

winforms-mvvm-best-practices/VB/EventToCommandBehaviorParametersConverters/PassingParametersToCommandsUserControl.vb#L26

vb
label.AutoSizeMode = LabelAutoSizeMode.None
label.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center
label.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center

winforms-docking-display-custom-header-buttons/VB/Form1.vb#L36

vb
If (e.Button Is panelContainer1.CustomHeaderButtons(4)) Then
    TryCast(panelContainer1.ActiveChild.ControlContainer.Controls(0), MemoEdit).Properties.Appearance.TextOptions.HAlignment = HorzAlignment.Near
End If

winforms-grid-copy-cells-in-biff8-format-using-excel-export-api/VB/gridCopyToClipboardExample/CopyToClipboardHelper.vb#L72

vb
' Apply alignment
Dim alignment As XlCellAlignment = New XlCellAlignment() With {.WrapText = appearance.TextOptions.WordWrap.HasFlag(WordWrap.Wrap), .VerticalAlignment = ConvertAlignment(appearance.TextOptions.VAlignment), .HorizontalAlignment = ConvertAlignment(appearance.TextOptions.HAlignment)}
cell.ApplyFormatting(alignment)

winforms-xtraform-center-caption/VB/WindowsApplication1/Custom Form Painter/CustomFormPainter.vb#L41

vb
appearance.TextOptions.Trimming = Trimming.EllipsisCharacter
appearance.TextOptions.HAlignment = CaptionAlignment
If AllowHtmlDraw Then

winforms-dashboard-get-underlying-data-for-clicked-item/VB/Dashboard_UnderlyingDataWin/Form1.vb#L25

vb
lbl.AutoSizeMode = LabelAutoSizeMode.None
lbl.Appearance.TextOptions.HAlignment = HorzAlignment.Center
lbl.Appearance.TextOptions.VAlignment = VertAlignment.Center

See Also

Trimming

VAlignment

WordWrap

TextOptions Class

TextOptions Members

DevExpress.Utils Namespace