Skip to main content
A newer version of this page is available.
All docs
V18.2

How to: Position Floating Picture

The following code snippet positions a floating picture by specifying the Shape.Offset from the top and left margins. To allow absolute positioning, the Shape.HorizontalAlignment and Shape.VerticalAlignment properties should be set to None.

This example moves a floating object to a position where its upper left corner is located at 4.5 cm to the right of the left margin and 2 cm below the top margin.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.

document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.Unit = DevExpress.Office.DocumentUnit.Centimeter;
Shape myPicture = document.Shapes[1];
// Clear the qualitative positioning to allow positioning by specifying the numerical offset.
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.None;
myPicture.VerticalAlignment = ShapeVerticalAlignment.None;
// Specify the reference item for positioning.
myPicture.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.LeftMargin;
myPicture.RelativeVerticalPosition = ShapeRelativeVerticalPosition.TopMargin;
// Specify the offset value.
myPicture.Offset = new System.Drawing.PointF(4.5f, 2.0f);