Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
HtmlElement Class
 OffsetParent Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
HtmlElement..::.OffsetParent Property

Gets the element from which OffsetRectangle is calculated.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public ReadOnly Property OffsetParent As HtmlElement
C#
public HtmlElement OffsetParent { get; }
Visual C++
public:
property HtmlElement^ OffsetParent {
    HtmlElement^ get ();
}
F#
member OffsetParent : HtmlElement

Property Value

Type: System.Windows.Forms..::.HtmlElement
The element from which the offsets are calculated.
If an element's parent or another element in the element's hierarchy uses relative or absolute positioning, OffsetParent will be the first relatively or absolutely positioned element in which the current element is nested. If none of the elements above the current element are absolutely or relatively positioned, OffsetParent will be the BODY tag of the document.

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; and absolute positioning, in which the element is given a fixed coordinate position relative to the upper-left corner of the document.

When a document's elements use relative or absolute positioning, you can use OffsetParent to calculate an element's coordinate position in the client area.

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:

<HTML>
    <BODY id="documentBody">

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

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

        <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>
            </DIV>
        </DIV>

    </BODY>
</HTML>
Visual Basic
Private Sub GetOffsets()
    Dim Str As String = ""
    Dim Doc As HtmlDocument = WebBrowser1.Document

    For Each Elem As HtmlElement In Doc.GetElementsByTagName("SPAN")
        Str &= "OffsetParent for " & Elem.Id & " is " & Elem.OffsetParent.Id
        Str &= "; OffsetRectangle is " & Elem.OffsetRectangle.ToString() & vbCrLf
    Next

    MessageBox.Show(Str)
End Sub
C#
        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";
            }

            MessageBox.Show(str);
        }

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker