HtmlWindow.Close Method

Definition

Closes the window.

C#
public void Close();

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 was written under the assumption that your form has a WebBrowser control named WebBrowser1, a Button named Button1, and a Timer class named Timer1. To run this example successfully, change the first argument supplied to OpenNew to a valid URL.

C#
HtmlWindow balanceWindow;

private void balanceWindowButton_Click(object sender, EventArgs e)
{
    if (!(webBrowser1.Document == null)) 
    {
        balanceWindow = webBrowser1.Document.Window.OpenNew(new Uri("http://www.adatum.com/viewBalances.aspx"), "dialogHeight: 250px; dialogWidth: 300px; " +
        " dialogTop: 300px; dialogLeft: 300px; edge: Sunken; center: Yes; help: Yes; " +
        "resizable: No; status: No;");

        //Listen for activity on the document.
        webBrowser1.Document.Click += new HtmlElementEventHandler(Document_Click);

        windowTimeout.Interval = 300000;
        windowTimeout.Start();
    }
}

private void Document_Click(object sender, HtmlElementEventArgs e)
{
    windowTimeout.Stop();
    windowTimeout.Start();
}

private void windowTimeout_Tick(object sender, EventArgs e) 
{
    if (!balanceWindow.IsClosed) 
    {
        balanceWindow.Close();
        windowTimeout.Stop();
    }
}

Remarks

Use the IsClosed property to determine if the window is already closed. If the window is already closed, this method has no effect.

When you create new windows using Open or OpenNew, Close causes the HTML Document Object Model to open a new instance of Internet Explorer. If you don't call Close on all of the windows you have created, this instance of Internet Explorer will remain running even after your application closes.

Applies to

Produkt Versioner
.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