Shape.RelativeHorizontalPosition Property
Gets or sets the element to which the shape’s horizontal position is relative.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.1.Core.dll
NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation
Declaration
Property Value
Type | Description |
---|---|
ShapeRelativeHorizontalPosition | Defines the element relative to which the shape is positioned horizontally. |
Available values:
Name | Description |
---|---|
Page | The shape’s position is relative to the page. |
Character | The shape’s position is relative to the character that contains the shape’s anchor. |
Column | The shape’s position is relative to the column that contains the anchoring paragraph. |
Margin | The shape’s position is relative to page margins. |
LeftMargin | The shape’s position is relative to the left margin. |
RightMargin | The shape’s position is relative to the right margin. |
InsideMargin | The shape’s position is relative to the inside margin (i.e., the left margin for odd pages, and the right margin for even pages). The Rich Text Editor positions the shape relative to the left margin for both odd and even pages. |
OutsideMargin | The shape’s position is relative to the outside margin (i.e., the right margin for odd pages, and the left margin for even pages). The Rich Text Editor positions the shape relative to the right margin for both odd and even pages. |
Remarks
Use one of the following methods to specify the position of a floating shape or picture in a document.
Align a Shape Horizontally and Vertically
Alignment | Specify the alignment type | Relative to |
---|---|---|
Horizontal | Shape.HorizontalAlignment | Shape.RelativeHorizontalPosition |
Vertical | Shape.VerticalAlignment | Shape.RelativeVerticalPosition |
The following example displays a rectangle in the center of the page below the top margin:
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;
Specify the Absolute Position
Position | Define the offset | Relative to |
---|---|---|
Horizontal | Shape.OffsetX | Shape.RelativeHorizontalPosition |
Vertical | Shape.OffsetY | Shape.RelativeVerticalPosition |
The Shape.Offset property specifies both the horizontal and vertical positions.
Note
The Offset properties are in effect when the Shape.HorizontalAlignment and Shape.VerticalAlignment properties are set to None.
The example below creates a rectangle and places it on the page as follows:
the absolute horizontal position is two inches to the right of the page;
the absolute vertical position is one inch below the page.
Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a rectangle.
Shape rectangle = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new SizeF(2.5f, 1.5f));
// Specify the rectangle position on the page.
rectangle.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Page;
rectangle.OffsetX = 2;
rectangle.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Page;
rectangle.OffsetY = 1;
Specify the Relative Position
Position | Define the offset (in percentage) | Relative to |
---|---|---|
Horizontal | Shape.OffsetXRelative | Shape.RelativeHorizontalPosition |
Vertical | Shape.OffsetYRelative | Shape.RelativeVerticalPosition |
The Shape.OffsetRelative property specifies both the horizontal and vertical relative positions.
Note
The OffsetRelative properties are in effect when the Shape.HorizontalAlignment and Shape.VerticalAlignment properties are set to None.
The example below creates a rectangle and places it on the page as follows:
the horizontal offset is equal to 20% of the page width,
the vertical offset is equal to 10% of the page height.
Document document = wordProcessor.Document;
// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a rectangle.
Shape rectangle = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new SizeF(2.5f, 1.5f));
// Specify the rectangle position on the page.
rectangle.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Page;
rectangle.OffsetXRelative = 0.2f;
rectangle.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Page;
rectangle.OffsetYRelative = 0.1f;
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the RelativeHorizontalPosition 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.