Export (0) Print
Expand All

HtmlWindow Class

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

System.Object
  System.Windows.Forms.HtmlWindow

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

[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public sealed class HtmlWindow

The HtmlWindow type exposes the following members.

  NameDescription
Public propertyDocumentGets the HTML document contained within the window.
Public propertyDomWindowGets the unmanaged interface wrapped by this class.
Public propertyFramesGets a reference to each of the FRAME elements defined within the Web page.
Public propertyHistoryGets an object containing the user's most recently visited URLs.
Public propertyIsClosedGets a value indicating whether this window is open or closed.
Public propertyNameGets or sets the name of the window.
Public propertyOpenerGets a reference to the window that opened the current window.
Public propertyParentGets the window which resides above the current one in a page containing frames.
Public propertyPositionGets the position of the window's client area on the screen.
Public propertySizeGets or sets the size of the current window.
Public propertyStatusBarTextGets or sets the text displayed in the status bar of a window.
Public propertyUrlGets the URL corresponding to the current item displayed in the window.
Public propertyWindowFrameElementGets the frame element corresponding to this window.
Top

  NameDescription
Public methodAlertDisplays a message box.
Public methodAttachEventHandlerAdds an event handler for the named HTML DOM event.
Public methodCloseCloses the window.
Public methodConfirmDisplays a dialog box with a message and buttons to solicit a yes/no response.
Public methodDetachEventHandlerRemoves the named event handler.
Public methodEqualsTests the object for equality against the current object. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFocusPuts the focus on the current window.
Public methodGetHashCodeServes as a hash function for a particular type. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodMoveTo(Point)Moves the window to the specified coordinates on the screen.
Public methodMoveTo(Int32, Int32)Moves the window to the specified coordinates on the screen.
Public methodNavigate(String)Displays or downloads the new content located at the specified URL.
Public methodNavigate(Uri)Displays a new document in the current window.
Public methodOpen(String, String, String, Boolean)Displays a file in the named window.
Public methodOpen(Uri, String, String, Boolean)Displays a file in the named window.
Public methodOpenNew(String, String)Displays a file in a new window.
Public methodOpenNew(Uri, String)Displays a file in a new window.
Public methodPromptShows a dialog box that displays a message and a text box to the user.
Public methodRemoveFocusTakes focus off of the current window.
Public methodResizeTo(Size)Changes the size of the window to the specified dimensions.
Public methodResizeTo(Int32, Int32)Changes the size of the window to the specified dimensions.
Public methodScrollTo(Point)Moves the window to the specified coordinates.
Public methodScrollTo(Int32, Int32)Scrolls the window to the designated position.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventErrorOccurs when script running inside of the window encounters a run-time error.
Public eventGotFocusOccurs when the current window obtains user input focus.
Public eventLoadOccurs when the window's document and all of its elements have finished initializing.
Public eventLostFocusOccurs when user input focus has left the window.
Public eventResizeOccurs when the user uses the mouse to change the dimensions of the window.
Public eventScrollOccurs when the user scrolls through the window to view off-screen text.
Public eventUnloadOccurs when the current page is unloading, and a new page is about to be displayed.
Top

  NameDescription
Public operatorStatic memberEqualityTests the two HtmlWindow objects for equality.
Public operatorStatic memberInequalityTests two HtmlWindow objects for inequality.
Top

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 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);
			}
		}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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

Community Additions

ADD
Show:
© 2014 Microsoft