HtmlWindow.Close 方法

定义

关闭窗口。

public:
 void Close();
public void Close ();
member this.Close : unit -> unit
Public Sub Close ()

示例

下面的代码示例将打开一个窗口,如果用户在过去五分钟内未使用过窗口,则会将其关闭。 代码示例是在假定窗体具有WebBrowser名为 WebBrowser1的控件和Button名为 TimerButton1的类Timer1的假设下编写的。 若要成功运行此示例,请将提供给 OpenNew 的第一个参数更改为有效的 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

注解

IsClosed使用 属性确定窗口是否已关闭。 如果窗口已关闭,则此方法不起作用。

使用 OpenOpenNew创建新窗口时, Close 会导致 HTML 文档对象模型打开 Internet Explorer 的新实例。 如果不在创建的所有窗口上调用 Close ,即使应用程序关闭,此 Internet Explorer 实例仍将保持运行状态。

适用于

另请参阅