This documentation is archived and is not being maintained.

HtmlWindow Class

Note: This class is new in the .NET Framework version 2.0.

Represents the logical window that contains one or more instances of HtmlDocument.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

Public NotInheritable Class HtmlWindow
Dim instance As HtmlWindow

public final class HtmlWindow
public final class HtmlWindow

HtmlWindow should not be confused with the concept of a window in Windows Forms or the Win32 API; there is no HWND or similar Windows resource that corresponds directly to an instance of HtmlWindow. Rather, HtmlWindow provides high-level descriptions of a document's location on a user's screen, as well as methods for interacting with users by way of prompts and dialog boxes. HtmlWindow acts as a logical container for a Web page's documents and its metadata, such as the document's location and the capabilities of the Web browser.

A Web page consists of a single document, or a FRAMESET containing one or more FRAME elements, each of which hosts its own document. Web developers use framesets to show logically related pages side by side (for example, a content page next to a navigation page). When a page consists of a single document, you can access it through the Document property of HtmlWindow; if the page uses frames, you can access their documents through the Frames collection, which consists of one or more HtmlWindow objects.

When your host the WebBrowser control in a Windows Forms application, you can choose to interact with the user using standard Windows Forms classes, such as Form or MessageBox, or you can use methods on HtmlWindow defined for this purpose. The Alert method presents a simple dialog box with custom text and an OK button; Prompt presents a line of custom text and a text input field to the user; and Confirm presents a dialog box with a line of custom text and OK and Cancel buttons.

You can use HtmlWindow to open new windows containing new documents. Open loads the specified URL into the named window, creating it if it does not already exist, while OpenNew always opens its URL in a newly created window.

The following code example contains two methods. The first opens a URL in a window named displayWindow, which it creates with a status bar displayed. The second opens another URL in the same window, but specifies that only the location bar should be displayed. Notice that the dimensions of the window and the controls that are displayed depends on which URL is opened first. The code example requires that your form contains a WebBrowser control named WebBrowser1.

Private Sub DisplayFirstUrl()
    If (Not WebBrowser1.Document Is Nothing) Then
        With WebBrowser1.Document
            ' If this is called first, the window will only have a status bar.
            .Window.Open(New Uri(""), "displayWindow", "status=yes,width=200,height=400", False)
        End With
    End If
End Sub

Private Sub DisplaySecondUrl()
    If (Not WebBrowser1.Document Is Nothing) Then
        With WebBrowser1.Document
            ' If this is called first, the window will only have an Address bar.
            .Window.Open(New Uri(""), "displayWindow", "width=400,height=200,location=yes", False)
        End With
    End If
End Sub


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0