HtmlWindow.IsClosed 屬性

定義

取得值,表示這個視窗已開啟還是關閉。

public:
 property bool IsClosed { bool get(); };
public bool IsClosed { get; }
member this.IsClosed : bool
Public ReadOnly Property IsClosed As Boolean

屬性值

Boolean

如果這個視窗在螢幕上仍是開啟的,則為 true;否則為 false

範例

下列程式碼範例會開啟視窗,如果使用者在過去五分鐘內未使用它,則會將其關閉。 程式碼範例會要求表單具有 WebBrowser 名為 的控制項、 Button 名為 WebBrowser1 Button1 的 ,以及 Timer 名為 的 Timer1 類別。

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));
            }
        }
    }
}
Private Sub ResetFrames()
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim FrameElement As HtmlElement
        Dim DocWindow As HtmlWindow = WebBrowser1.Document.Window

        For Each FrameWindow As HtmlWindow In DocWindow.Frames
            FrameElement = FrameWindow.WindowFrameElement
            Dim OriginalUrl As String = FrameElement.GetAttribute("SRC")

            If (Not OriginalUrl.Equals(FrameWindow.Url.ToString())) Then
                FrameWindow.Navigate(New Uri(OriginalUrl))
            End If
        Next
    End If
End Sub

備註

HtmlWindow如果使用者已關閉 ,或透過呼叫 Close 方法,嘗試流覽至新的 URL 或存取視窗的檔將會導致錯誤。 使用這個屬性來判斷是否安全呼叫目前視窗物件上的屬性和方法。

適用於

另請參閱