HtmlWindow.Close Method ()

 

Closes the window.

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

public void Close()

Use the IsClosed property to determine if the window is already closed. If the window is already closed, this method will have 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 do not call Close on all of the windows you have created, this instance of Internet Explorer will remain running even after your application closes.

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.

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

.NET Framework
Available since 2.0
Return to top
Show: