Search Results for

    Show / Hide Table of Contents

    Class ElementPosition

    Represents the position of an element with horizontal and vertical coordinates.

    Inheritance
    System.Object
    ElementPosition
    Namespace: IronWord.Models
    Assembly: IronWord.dll
    Syntax
    public class ElementPosition : Object

    Where an element sits on the page, given as horizontal and vertical coordinates, is what ElementPosition records in a Word document. A developer assigns it to a positioned element, such as a floating image or shape, to place that element at exact coordinates rather than letting it flow with the text.

    Create one with new ElementPosition() and set its coordinates. The X and Y properties hold the horizontal and vertical offsets as integers measured in points, where one inch equals 72 points, and the values are converted to points automatically when read or written. For work in other units, the position offers paired getters and setters: SetXPosition and SetYPosition each take a value and a MeasurementUnit, and GetXPosition and GetYPosition return the coordinate converted to a requested unit.

    That unit-aware pairing is the reason to prefer the methods over the raw X and Y properties when a layout is expressed in inches, centimeters, or millimeters. A developer can set the horizontal position in centimeters and read it back in points, or the reverse, without converting by hand, while the underlying coordinate stays in the document's native points. The same MeasurementUnit argument drives both the set and get calls, so a layout defined in one unit stays consistent end to end. Because a single ElementPosition carries both axes, the same object describes a complete placement and can be reused for elements that should align at the same spot, or copied and nudged for elements that sit just beside one another.

    var position = new ElementPosition();
    position.SetXPosition(2, MeasurementUnit.Cm);
    position.SetYPosition(1.5, MeasurementUnit.Cm);

    The add image how-to places visual content that can be positioned, and the document element tutorial shows how elements assemble in a document.

    Constructors

    ElementPosition()

    Declaration
    public ElementPosition()

    Properties

    X

    Gets or sets the horizontal coordinate (X) of the element measured in points (1 inch = 72 points).

    Declaration
    public int X { get; set; }
    Property Value
    Type Description
    System.Int32
    Remarks

    The X coordinate is automatically converted to points (1 inch = 72 points) when getting or setting the value.

    Y

    Gets or sets the vertical coordinate (Y) of the element measured in points (1 inch = 72 points).

    Declaration
    public int Y { get; set; }
    Property Value
    Type Description
    System.Int32
    Remarks

    The Y coordinate is automatically converted to points (1 inch = 72 points) when getting or setting the value.

    Methods

    GetXPosition(MeasurementUnit)

    Gets the horizontal coordinate (X) of the element in the specified measurement unit.

    Declaration
    public double GetXPosition(MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    MeasurementUnit measurementUnit

    The desired unit of measurement.

    Returns
    Type Description
    System.Double

    The horizontal coordinate in the specified measurement unit.

    GetYPosition(MeasurementUnit)

    Gets the vertical coordinate (Y) of the element in the specified measurement unit.

    Declaration
    public double GetYPosition(MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    MeasurementUnit measurementUnit

    The desired unit of measurement.

    Returns
    Type Description
    System.Double

    The vertical coordinate in the specified measurement unit.

    SetXPosition(Double, MeasurementUnit)

    Sets the horizontal coordinate (X) of the element using the specified value and measurement unit.

    Declaration
    public void SetXPosition(double x, MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    System.Double x

    The horizontal coordinate value.

    MeasurementUnit measurementUnit

    The unit of measurement for the provided value.

    SetYPosition(Double, MeasurementUnit)

    Sets the vertical coordinate (Y) of the element using the specified value and measurement unit.

    Declaration
    public void SetYPosition(double y, MeasurementUnit measurementUnit)
    Parameters
    Type Name Description
    System.Double y

    The vertical coordinate value.

    MeasurementUnit measurementUnit

    The unit of measurement for the provided value.

    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet