HtmlWindowCollection HtmlWindowCollection HtmlWindowCollection HtmlWindowCollection Class

定义

表示另一个 HtmlWindow 中包含的窗口。Represents the windows contained within another 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
继承
HtmlWindowCollectionHtmlWindowCollectionHtmlWindowCollectionHtmlWindowCollection
实现

示例

下面的代码示例检查包含框架的页中的每个文档并创建一个表, 其中包含每个页面的所有传出超链接, 以便以后检查。The following code example inspects each document within a page containing frames and creates a table of all of the outgoing hyperlinks from each page for future inspection.

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 页面。An HTML document may consist of a FRAMESET that defines multiple fixed FRAME objects, each of which contains its own HTML page. 或者, 文档可能包含多个IFRAME对象, 这些对象可将文档随意定位到其他文档中。Alternatively, a document may contain a number of IFRAME objects, which can position documents arbitrarily inside of other documents. FRAME对象和IFRAME对象在其最HtmlWindowCollection顶层表示, 后者包含类型HtmlWindow为的元素。FRAME objects and IFRAME objects are represented at their top-most level by an HtmlWindowCollection, which contains elements of type HtmlWindow.

HtmlWindowCollectionIEnumerator支持接口, 以便它可用于循环构造。HtmlWindowCollection supports the IEnumerator interface so that it can be used in loop constructs. 它还定义了一个 Item 方法, 该方法允许通过方法调用或使用标准数组语法访问集合中的元素。It also defines an Item method, which allows access to the elements of the collection either via a method call or using standard array syntax.

Open如果使用HtmlWindowCollectionOpenNew方法创建新窗口, 并且这些 windows 承载的文档包含FRAMEIFRAME元素, 则这些元素将出现在父页的中。If you create new windows with the Open or OpenNew methods, and the documents hosted by these windows contain FRAME or IFRAME elements, that these elements will appear in the HtmlWindowCollection of the parent page.

有关框架的详细信息, 请参阅Frames属性的文档。For more information on frames, see the documentation for the Frames property.

属性

Count Count Count Count

获取集合中的元素数。Gets the number of elements in the collection.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

通过提供框架在集合中的位置检索框架窗口。Retrieves a frame window by supplying the frame's position in the collection.

Item[String] Item[String] Item[String] Item[String]

通过提供框架的名称检索框架窗口。Retrieves a frame window by supplying the frame's name.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回一个枚举数,该枚举数可循环访问 HtmlWindowCollection 中的所有元素。Returns an enumerator that can iterate through all elements in the HtmlWindowCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

将该集合的元素复制到 Array(从特定的 Array 索引开始)。Copies the elements of the collection to an Array, starting at a particular Array index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

获取一个值,该值指示对集合的访问是否为同步的(线程安全)。Gets a value indicating whether access to the collection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

获取可用于同步对集合的访问的对象。Gets an object that can be used to synchronize access to the collection.

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅