Export (0) Print
Expand All

HtmlWindow.IsClosed Property

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

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

public bool IsClosed { get; }

Property Value

Type: System.Boolean
true if the window is still open on the screen; otherwise, false.

If the HtmlWindow has been closed by the user or by way of a call to the Close method, attempting to navigate to a new URL or access the window's document will result in an error. Use this property to determine whether it is safe to call properties and methods on the current window object.

The following code example opens a window, and closes it if the user has not used it in the past five minutes. The code example requires that your form has a WebBrowser control named WebBrowser1, a Button named Button1, and a Timer class named Timer1.

		private void ResetFrames()
        {
			if (!(webBrowser1.Document == null)) 
			{
				HtmlElement frameElement = null;
				HtmlWindow docWindow = webBrowser1.Document.Window;

				foreach (HtmlWindow frameWindow in docWindow.Frames)
				{
					frameElement = frameWindow.WindowFrameElement;
					String originalUrl = frameElement.GetAttribute("SRC");

					if (!originalUrl.Equals(frameWindow.Url.ToString())) 
					{
						frameWindow.Navigate(new Uri(originalUrl));
					}
				}
			}
		}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft