Muokkaa

Jaa


HtmlWindow.Close Method

Definition

Closes the window.

public:
 void Close();
public void Close ();
member this.Close : unit -> unit
Public Sub 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.

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();
    }
}
Dim BalanceWindow As HtmlWindow

Private Sub BalanceWindowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BalanceWindowButton.Click
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            BalanceWindow = .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.


            WindowTimeout.Interval = 300000
            WindowTimeout.Start()
        End With
    End If
End Sub

Private Sub Document_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    WindowTimeout.Stop()
    WindowTimeout.Start()
End Sub

Private Sub WindowTimeout_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WindowTimeout.Tick
    If (Not BalanceWindow.IsClosed) Then
        BalanceWindow.Close()
        WindowTimeout.Stop()
    End If
End Sub

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

See also