HtmlWindow HtmlWindow HtmlWindow HtmlWindow Class

Definition

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

public ref class HtmlWindow sealed
public sealed class HtmlWindow
type HtmlWindow = class
Public NotInheritable Class HtmlWindow
Inheritance
HtmlWindowHtmlWindowHtmlWindowHtmlWindow

Examples

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 void DisplayFirstUrl()
{
	if (webBrowser1.Document != null)
	{
		//If this is called first, the window will only have a status bar.
		webBrowser1.Document.Window.Open(new Uri("http://www.microsoft.com/"), "displayWindow", "status=yes,width=200,height=400", false);
	}
}

private void DisplaySecondUrl()
{
	if (webBrowser1.Document != null)
	{
		// If this is called first, the window will only have an Address bar.
		webBrowser1.Document.Window.Open(new Uri("http://msdn.microsoft.com/"), "displayWindow", "width=400,height=200,location=yes", false);
	}
}
Private Sub DisplayFirstUrl()
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            ' If this is called first, the window will only have a status bar.
            .Window.Open(New Uri("http://www.microsoft.com/"), "displayWindow", "status=yes,width=200,height=400", False)
        End With
    End If
End Sub

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

Remarks

HtmlWindow should not be confused with the concept of a window in Windows Forms or the Windows 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.

Properties

Document Document Document Document

Gets the HTML document contained within the window.

DomWindow DomWindow DomWindow DomWindow

Gets the unmanaged interface wrapped by this class.

Frames Frames Frames Frames

Gets a reference to each of the FRAME elements defined within the Web page.

History History History History

Gets an object containing the user's most recently visited URLs.

IsClosed IsClosed IsClosed IsClosed

Gets a value indicating whether this window is open or closed.

Name Name Name Name

Gets or sets the name of the window.

Opener Opener Opener Opener

Gets a reference to the window that opened the current window.

Parent Parent Parent Parent

Gets the window which resides above the current one in a page containing frames.

Position Position Position Position

Gets the position of the window's client area on the screen.

Size Size Size Size

Gets or sets the size of the current window.

StatusBarText StatusBarText StatusBarText StatusBarText

Gets or sets the text displayed in the status bar of a window.

Url Url Url Url

Gets the URL corresponding to the current item displayed in the window.

WindowFrameElement WindowFrameElement WindowFrameElement WindowFrameElement

Gets the frame element corresponding to this window.

Methods

Alert(String) Alert(String) Alert(String) Alert(String)

Displays a message box.

AttachEventHandler(String, EventHandler) AttachEventHandler(String, EventHandler) AttachEventHandler(String, EventHandler) AttachEventHandler(String, EventHandler)

Adds an event handler for the named HTML DOM event.

Close() Close() Close() Close()

Closes the window.

Confirm(String) Confirm(String) Confirm(String) Confirm(String)

Displays a dialog box with a message and buttons to solicit a yes/no response.

DetachEventHandler(String, EventHandler) DetachEventHandler(String, EventHandler) DetachEventHandler(String, EventHandler) DetachEventHandler(String, EventHandler)

Removes the named event handler.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Tests the object for equality against the current object.

Focus() Focus() Focus() Focus()

Puts the focus on the current window.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as a hash function for a particular type.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MoveTo(Int32, Int32) MoveTo(Int32, Int32) MoveTo(Int32, Int32) MoveTo(Int32, Int32)

Moves the window to the specified coordinates on the screen.

MoveTo(Point) MoveTo(Point) MoveTo(Point) MoveTo(Point)

Moves the window to the specified coordinates on the screen.

Navigate(String) Navigate(String) Navigate(String) Navigate(String)

Displays or downloads the new content located at the specified URL.

Navigate(Uri) Navigate(Uri) Navigate(Uri) Navigate(Uri)

Displays a new document in the current window.

Open(String, String, String, Boolean) Open(String, String, String, Boolean) Open(String, String, String, Boolean) Open(String, String, String, Boolean)

Displays a file in the named window.

Open(Uri, String, String, Boolean) Open(Uri, String, String, Boolean) Open(Uri, String, String, Boolean) Open(Uri, String, String, Boolean)

Displays a file in the named window.

OpenNew(String, String) OpenNew(String, String) OpenNew(String, String) OpenNew(String, String)

Displays a file in a new window.

OpenNew(Uri, String) OpenNew(Uri, String) OpenNew(Uri, String) OpenNew(Uri, String)

Displays a file in a new window.

Prompt(String, String) Prompt(String, String) Prompt(String, String) Prompt(String, String)

Shows a dialog box that displays a message and a text box to the user.

RemoveFocus() RemoveFocus() RemoveFocus() RemoveFocus()

Takes focus off of the current window.

ResizeTo(Int32, Int32) ResizeTo(Int32, Int32) ResizeTo(Int32, Int32) ResizeTo(Int32, Int32)

Changes the size of the window to the specified dimensions.

ResizeTo(Size) ResizeTo(Size) ResizeTo(Size) ResizeTo(Size)

Changes the size of the window to the specified dimensions.

ScrollTo(Int32, Int32) ScrollTo(Int32, Int32) ScrollTo(Int32, Int32) ScrollTo(Int32, Int32)

Scrolls the window to the designated position.

ScrollTo(Point) ScrollTo(Point) ScrollTo(Point) ScrollTo(Point)

Moves the window to the specified coordinates.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

Error Error Error Error

Occurs when script running inside of the window encounters a run-time error.

GotFocus GotFocus GotFocus GotFocus

Occurs when the current window obtains user input focus.

Load Load Load Load

Occurs when the window's document and all of its elements have finished initializing.

LostFocus LostFocus LostFocus LostFocus

Occurs when user input focus has left the window.

Resize Resize Resize Resize

Occurs when the user uses the mouse to change the dimensions of the window.

Scroll Scroll Scroll Scroll

Occurs when the user scrolls through the window to view off-screen text.

Unload Unload Unload Unload

Occurs when the current page is unloading, and a new page is about to be displayed.

Operators

Equality(HtmlWindow, HtmlWindow) Equality(HtmlWindow, HtmlWindow) Equality(HtmlWindow, HtmlWindow) Equality(HtmlWindow, HtmlWindow)

Tests the two HtmlWindow objects for equality.

Inequality(HtmlWindow, HtmlWindow) Inequality(HtmlWindow, HtmlWindow) Inequality(HtmlWindow, HtmlWindow) Inequality(HtmlWindow, HtmlWindow)

Tests two HtmlWindow objects for inequality.

Applies to

See also