WebBrowser.Document 속성

정의

HtmlDocument 컨트롤에 현재 표시된 웹 페이지를 나타내는 WebBrowser를 가져옵니다.

public:
 property System::Windows::Forms::HtmlDocument ^ Document { System::Windows::Forms::HtmlDocument ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HtmlDocument Document { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HtmlDocument? Document { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Document : System.Windows.Forms.HtmlDocument
Public ReadOnly Property Document As HtmlDocument

속성 값

현재 페이지를 나타내는 HtmlDocument이거나, 페이지가 로드되지 않으면 null입니다.

특성

예외

WebBrowser 인스턴스가 더 이상 유효하지 않은 경우

내부 ActiveX IWebBrowser2 컨트롤에서 WebBrowser 인터페이스 구현에 대한 참조를 검색할 수 없는 경우

예제

다음 코드 예제를 사용 Document 하는 방법에 설명 합니다 에 대 Navigating 한 처리기에서 속성을 웹 페이지 양식이 채워졌는지 여부를 확인 하는 이벤트입니다. 입력 필드에 값이 없으면 탐색이 취소됩니다.

이 예제에서는 폼에는 WebBrowser 이라는 컨트롤 webBrowser1합니다.

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.DocumentText =
        "<html><body>Please enter your name:<br/>" +
        "<input type='text' name='userName'/><br/>" +
        "<a href='http://www.microsoft.com'>continue</a>" +
        "</body></html>";
    webBrowser1.Navigating += 
        new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}

private void webBrowser1_Navigating(object sender, 
    WebBrowserNavigatingEventArgs e)
{
    System.Windows.Forms.HtmlDocument document =
        this.webBrowser1.Document;

    if (document != null && document.All["userName"] != null && 
        String.IsNullOrEmpty(
        document.All["userName"].GetAttribute("value")))
    {
        e.Cancel = true;
        System.Windows.Forms.MessageBox.Show(
            "You must enter your name before you can navigate to " +
            e.Url.ToString());
    }
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
    Handles Me.Load

    webBrowser1.DocumentText = _
        "<html><body>Please enter your name:<br/>" & _
        "<input type='text' name='userName'/><br/>" & _
        "<a href='http://www.microsoft.com'>continue</a>" & _
        "</body></html>"

End Sub

Private Sub webBrowser1_Navigating( _
    ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _
    Handles webBrowser1.Navigating

    Dim document As System.Windows.Forms.HtmlDocument = _
        webBrowser1.Document
    If document IsNot Nothing And _
        document.All("userName") IsNot Nothing And _
        String.IsNullOrEmpty( _
        document.All("userName").GetAttribute("value")) Then

        e.Cancel = True
        MsgBox("You must enter your name before you can navigate to " & _
            e.Url.ToString())
    End If

End Sub

설명

HTML DOM(문서 개체 모델)을 통해 컨트롤에 표시되는 웹 페이지의 콘텐츠에 WebBrowser 액세스하려면 이 속성을 사용합니다. 예를 들어, Windows Forms 애플리케이션에서 웹 기반 컨트롤을 사용 하려는 경우 유용 합니다.

와 함께에서이 속성을 사용할 수는 ObjectForScripting 속성에 표시 되는 웹 페이지 간의 양방향 통신을 구현 하는 WebBrowser 컨트롤과 애플리케이션입니다. 사용 된 HtmlDocument.InvokeScript 클라이언트 애플리케이션 코드에서 웹 페이지에 구현 하는 스크립트 메서드를 호출 하는 방법입니다. 스크립트 코드를 통해 애플리케이션에 액세스할 수는 window.external 호스트 액세스용으로 제공 하는 기본 제공 DOM 개체는 및에 대 한 지정 된 개체에 매핑되는 개체는 ObjectForScripting 속성.

문자열로 웹 페이지의 내용에 액세스 하려면 사용 된 DocumentText 속성입니다. 로 웹 페이지의 Stream콘텐츠에 액세스 하려면 사용 된 DocumentStream 속성입니다.

적용 대상

추가 정보