Export (0) Print
Expand All

HtmlElement.OffsetRectangle Property

Gets the location of an element relative to its parent.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Rectangle OffsetRectangle { get; }

Property Value

Type: System.Drawing.Rectangle
The x- and y-coordinate positions of the element, and its width and its height, in relation to its parent.
If an element's parent is relatively or absolutely positioned, OffsetRectangle will return the offset of the parent element. If the element itself is relatively positioned with respect to its parent, OffsetRectangle will return the offset from its parent.

Elements can be positioned on an HTML page in one of three ways:

  • Default flow positioning.

  • Relative positioning, in which the element is offset by a fixed amount relative to its parent.

  • Absolute positioning, in which the element is given a fixed coordinate position relative to the upper-left corner of the document.

For more information about element positioning in HTML, see About Element Positioning.

The following code example shows how OffsetParent and OffsetRectangle differ for span1, span2 and span3:

    <BODY id="documentBody">

        <DIV id="div1">
            <SPAN id="span1">Placeholder text 1.</SPAN>

        <DIV id="div2" style="position:relative;top:100px;left:100px;">
            <SPAN id="span2">Placeholder text 2.</SPAN>

        <DIV id="div3" style="position:absolute;top:200px;left:200px;">
            <DIV id="div4" style="position:relative;top:100px;left:100px;">
                <SPAN id="span3">Placeholder text 3.</SPAN>

		private void GetOffsets()
			String str = "";
			HtmlDocument doc = webBrowser1.Document;

			foreach (HtmlElement elem in doc.GetElementsByTagName("SPAN"))
				str += "OffsetParent for " + elem.Id + " is " + elem.OffsetParent.Id;
				str += "; OffsetRectangle is " + elem.OffsetRectangle.ToString() + "\n";


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft