HtmlElement.Parent 속성

정의

현재 요소의 부모 요소를 가져옵니다.

public:
 property System::Windows::Forms::HtmlElement ^ Parent { System::Windows::Forms::HtmlElement ^ get(); };
public System.Windows.Forms.HtmlElement Parent { get; }
public System.Windows.Forms.HtmlElement? Parent { get; }
member this.Parent : System.Windows.Forms.HtmlElement
Public ReadOnly Property Parent As HtmlElement

속성 값

HTML 문서의 계층에서 현재 요소의 위에 있는 요소입니다.

예제

다음 코드 예제에서는 문서에서 모든 IMG 태그를 찾아 사용 하 여 Parent 는 다른 페이지에 하이퍼링크 되어 있는지 여부를 IMG 테스트 하는 속성입니다. 이 경우 코드는 태그의 IMG 특성에 ALT URL을 할당, 사용자가 이미지를 마우스로 이동 하는 위치를 볼 수 있도록 합니다.

private void AddUrlToTooltip()
{
    if (webBrowser1.Document != null)
    {
        foreach (HtmlElement elem in webBrowser1.Document.GetElementsByTagName("IMG"))
        {
            if (elem.Parent.TagName.Equals("A"))
            {
                String altStr = elem.GetAttribute("ALT");
                if (!(altStr == null) && (altStr.Length != 0))
                {
                    elem.SetAttribute("ALT", altStr + " - points to " + elem.Parent.GetAttribute("HREF"));
                }
                else
                {
                    elem.SetAttribute("ALT", "Points to " + elem.Parent.GetAttribute("HREF"));
                }
            }
        }
    }
}
Private Sub AddUrlToTooltip()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            For Each Elem As HtmlElement In .GetElementsByTagName("IMG")
                If (Elem.Parent.TagName.Equals("A")) Then
                    Dim AltStr As String = Elem.GetAttribute("ALT")
                    If (Not (AltStr Is Nothing) And (AltStr.Length <> 0)) Then
                        Elem.SetAttribute("ALT", AltStr & " - points to " & Elem.Parent.GetAttribute("HREF"))
                    Else
                        Elem.SetAttribute("ALT", "Points to " & Elem.Parent.GetAttribute("HREF"))
                    End If
                End If
            Next
        End With
    End If
End Sub

설명

속성은 Parent 요소의 컨텍스트를 검색할 수 있도록 합니다. 문서 개체 계층 구조의 모든 요소에 대해 발생할 수 있는 과 같은 Click이벤트 처리기 내에서 가장 유용합니다.

HTML 요소의 속성(HTML 문서의 맨 위)은 Parent 자신을 다시 가리킵니다. 루프 내에서 를 호출 Parent 하는 경우 루프의 중단 조건이 현재 요소의 형식과 속성의 Parent 형식을 비교하는지 확인합니다. 그렇지 않으면 코드가 무한 루프를 실행할 수 있습니다.

적용 대상

추가 정보