Back to Devexpress

Shape.HorizontalAlignment Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shape-3ad5fd0d.md

latest8.4 KB
Original Source

Shape.HorizontalAlignment Property

Specifies how a shape is aligned horizontally.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
ShapeHorizontalAlignment HorizontalAlignment { get; set; }
vb
Property HorizontalAlignment As ShapeHorizontalAlignment

Property Value

TypeDescription
ShapeHorizontalAlignment

An enumeration member that specifies the shape’s horizontal alignment.

|

Available values:

NameDescription
None

The Shape.OffsetX property specifies the shape’s position relative to the element defined by the Shape.RelativeHorizontalPosition property.

| | Left |

The shape is left-aligned relative to the element defined by the Shape.RelativeHorizontalPosition property.

| | Center |

The shape is centered relative to the element defined by the Shape.RelativeHorizontalPosition property.

| | Right |

The shape is right-aligned relative to the element defined by the Shape.RelativeHorizontalPosition property.

| | Inside |

The shape is left-aligned relative to the element defined by the Shape.RelativeHorizontalPosition property on odd pages, and right-aligned on even pages.

The Rich Text Editor left-aligns the shape relative to the given element for both odd and even pages.

| | Outside |

The shape is right-aligned relative to the element defined by the Shape.RelativeHorizontalPosition property on odd pages, and left-aligned on even pages.

The Rich Text Editor right-aligns the shape relative to the given element for both odd and even pages.

|

Remarks

Use the following properties to align a shape on the page:

The following example displays a rectangle in the center of the page below the top margin:

csharp
Document document = wordProcessor.Document;
// Create a rectangle.
Shape rectangle = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new SizeF(500, 300));
// Align the rectangle horizontally and vertically.
rectangle.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Page;
rectangle.HorizontalAlignment = ShapeHorizontalAlignment.Center;
rectangle.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Margin;
rectangle.VerticalAlignment = ShapeVerticalAlignment.Top;
vb
Dim document As Document = wordProcessor.Document
' Create a rectangle.
Dim rectangle As Shape = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, New SizeF(500, 300))
' Align the rectangle horizontally and vertically.
rectangle.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Page
rectangle.HorizontalAlignment = ShapeHorizontalAlignment.Center
rectangle.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Margin
rectangle.VerticalAlignment = ShapeVerticalAlignment.Top

Set the alignment values to None and use the Shape.OffsetX and Shape.OffsetY properties to specify the absolute position of the shape on the page.

The following code snippets (auto-collected from DevExpress Examples) contain references to the HorizontalAlignment 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-richedit-document-api/CS/RichEditAPISample/CodeExamples/Shapes.cs#L18

csharp
DocumentImageSource.FromFile("beverages.png"));
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
#endregion #AddFloatingPicture

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L27

csharp
DocumentImageSource.FromStream(s));
    myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
}

word-document-api-examples/CS/CodeExamples/ShapesActions.cs#L34

csharp
// Specify the picture alignment.
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
#endregion #AddFloatingPicture

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L16

vb
Dim myPicture As DevExpress.XtraRichEdit.API.Native.Shape = document.Shapes.InsertPicture(document.CreatePosition(15), DevExpress.XtraRichEdit.API.Native.DocumentImageSource.FromFile("beverages.png"))
            myPicture.HorizontalAlignment = DevExpress.XtraRichEdit.API.Native.ShapeHorizontalAlignment.Center
#End Region ' #AddFloatingPicture

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L21

vb
Dim myPicture As Shape = document.Shapes.InsertPicture(document.CreatePosition(15), DocumentImageSource.FromStream(s))
    myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center
End Using

word-document-api-examples/VB/CodeExamples/ShapesActions.vb#L34

vb
' Specify the picture alignment.
            myPicture.HorizontalAlignment = DevExpress.XtraRichEdit.API.Native.ShapeHorizontalAlignment.Center
#End Region ' #AddFloatingPicture

See Also

RelativeHorizontalPosition

OffsetX

OffsetXRelative

Shape Interface

Shape Members

DevExpress.XtraRichEdit.API.Native Namespace