HtmlElement.OffsetRectangle Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the location of an element relative to its parent.
public:
property System::Drawing::Rectangle OffsetRectangle { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle OffsetRectangle { get; }
member this.OffsetRectangle : System.Drawing.Rectangle
Public ReadOnly Property OffsetRectangle As Rectangle
Property Value
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.
Examples
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>
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);
}
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
Remarks
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.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기