Skip to main content
A newer version of this page is available. .

How to: Position a Picture

The following code snippet positions a 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.

document.LoadDocument("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);