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 方法,该方法允许通过方法调用或使用标准数组语法访问集合的元素。

如果使用 或 OpenNew 方法创建新窗口Open,并且这些窗口承载的文档包含 FRAMEIFRAME 元素,则这些元素将显示在HtmlWindowCollection父页的 中。

有关帧的详细信息,请参阅 属性的文档 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

适用于

另请参阅