HtmlWindow.IsClosed Property

Definition

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

C#
public bool IsClosed { get; }

Property Value

true if the window is still open on the screen; otherwise, false.

Examples

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.

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

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also