WebBrowser.DocumentText 속성

정의

WebBrowser 컨트롤에 표시되는 페이지의 HTML 콘텐츠를 가져오거나 설정합니다.

public:
 property System::String ^ DocumentText { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
public string DocumentText { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DocumentText : string with get, set
Public Property DocumentText As String

속성 값

표시된 페이지의 HTML 텍스트이거나, 문서가 로드되지 않는 경우 빈 문자열("")입니다.

특성

예외

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

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

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다.는 DocumentText 프로그래밍 방식으로 표시 하는 속성의 문서 콘텐츠를 선택 합니다. 이 예제에서는 폼에는 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

설명

문자열 처리 도구를 사용하여 컨트롤에 표시되는 WebBrowser HTML 페이지의 내용을 조작하려는 경우 이 속성을 사용합니다. 예를 들어 이 속성을 사용하여 데이터베이스에서 페이지를 로드하거나 정규식을 사용하여 페이지를 분석할 수 있습니다. 이 속성을 설정하면 컨트롤은 WebBrowser 지정된 텍스트를 로드하기 전에 about:blank URL로 자동으로 이동합니다. 즉 Navigating, 이 속성을 설정할 때 , NavigatedDocumentCompleted 이벤트가 발생하고 속성 값 Url 이 더 이상 의미가 없습니다.

참고

이 속성에는 다른 문서가 요청된 경우에도 현재 문서의 텍스트가 포함됩니다. 이 속성의 값을 설정한 다음 즉시 다시 검색하면 컨트롤에 새 콘텐츠를 로드할 시간이 없는 경우 WebBrowser 검색된 값이 설정된 값과 다를 수 있습니다. 이벤트 처리기에서 새 값을 검색할 DocumentCompleted 수 있습니다. 또는 속성이 원래 설정한 값을 반환할 때까지 루프에서 메서드를 호출 Thread.Sleep 하여 문서가 로드될 때까지 DocumentText 스레드를 차단할 수 있습니다.

웹 페이지의 Stream콘텐츠에 액세스하려면 속성을 사용합니다 DocumentStream . 속성을 통해 HTML DOM(문서 개체 모델)을 사용하여 페이지 콘텐츠에 Document 액세스할 수도 있습니다.

적용 대상

추가 정보