HtmlWindowCollection 類別

定義

表示包含在另一個 HtmlWindow 中的視窗。

public ref class HtmlWindowCollection : System::Collections::ICollection
public class HtmlWindowCollection : System.Collections.ICollection
type HtmlWindowCollection = class
    interface ICollection
    interface IEnumerable
Public Class HtmlWindowCollection
Implements ICollection
繼承
HtmlWindowCollection
實作

範例

下列程式碼範例會檢查包含框架的頁面內的每份檔,並建立每個頁面所有傳出超連結的表格,以供日後檢查。

private void GetLinksFromFrames()
{
    Hashtable linksTable = new Hashtable();
    string frameUrl;

    if (!(webBrowser1.Document == null))
    {
        HtmlWindow currentWindow = webBrowser1.Document.Window;
        if (currentWindow.Frames.Count > 0)
        {
            foreach (HtmlWindow frame in currentWindow.Frames)
            {
                frameUrl = frame.Url.ToString();
                Hashtable frameLinksHash = new Hashtable();

                linksTable.Add(frameUrl, frameLinksHash);
                foreach (HtmlElement hrefElement in frame.Document.Links)
                {
                    frameLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");
                }
            }
        }
        else
        {
            Hashtable docLinksHash = new Hashtable();
            linksTable.Add(webBrowser1.Document.Url.ToString(), docLinksHash);

            foreach (HtmlElement hrefElement in webBrowser1.Document.Links)
            {
                docLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");
            }
        }
    }
}
Dim LinksTable As Hashtable

Private Sub GetLinksFromFrames()
    LinksTable = New Hashtable()
    Dim FrameUrl As String

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim CurrentWindow As HtmlWindow = .Window
            If (CurrentWindow.Frames.Count > 0) Then
                For Each Frame As HtmlWindow In CurrentWindow.Frames
                    FrameUrl = Frame.Url.ToString()
                    Dim FrameLinksHash As New Hashtable()
                    LinksTable.Add(FrameUrl, FrameLinksHash)

                    For Each HrefElement As HtmlElement In Frame.Document.Links
                        FrameLinksHash.Add(HrefElement.GetAttribute("HREF"), "Url")
                    Next
                Next
            Else
                Dim DocLinksHash As New Hashtable()
                LinksTable.Add(.Url.ToString(), DocLinksHash)

                For Each HrefElement As HtmlElement In .Links
                    DocLinksHash.Add(HrefElement.GetAttribute("HREF"), "Url")
                Next
            End If
        End With
    End If
End Sub

備註

HTML 檔案可能包含 FRAMESET 定義多個固定 FRAME 物件的 ,每個物件都包含自己的 HTML 頁面。 或者,檔可能包含一 IFRAME 些物件,這些物件可以在其他檔內任意放置檔。 FRAME 物件和 IFRAME 物件會以其 HtmlWindowCollection 最上層表示,其中包含 類型的 HtmlWindow 專案。

HtmlWindowCollectionIEnumerator支援 介面,使其可用於迴圈建構。 它也會定義 Item 方法,允許透過方法呼叫或使用標準陣列語法來存取集合的專案。

如果您使用 或 方法建立新的視窗 Open ,而且這些視窗所裝載的檔包含 FRAMEIFRAME 元素,這些元素會出現在父頁面的 中 HtmlWindowCollectionOpenNew

如需框架的詳細資訊,請參閱 屬性的檔 Frames

屬性

Count

取得集合中的項目數。

Item[Int32]

藉由提供集合中的框架位置來擷取框架視窗。

Item[String]

藉由提供框架的名稱來擷取框架視窗。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回可逐一查看 HtmlWindowCollection 中的所有項目的列舉值。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICollection.CopyTo(Array, Int32)

從特定的 Array 索引開始,將集合的項目複製至 Array

ICollection.IsSynchronized

取得值,表示是否同步化存取集合 (執行緒安全)。

ICollection.SyncRoot

取得物件,這個物件可以用來對集合進行同步存取。

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱