Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HtmlWindowCollection Class

Represents the windows contained within another HtmlWindow.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Class HtmlWindowCollection _
    Implements ICollection, IEnumerable
Visual Basic (Usage)
Dim instance As HtmlWindowCollection
C#
public class HtmlWindowCollection : ICollection, 
    IEnumerable
Visual C++
public ref class HtmlWindowCollection : ICollection, 
    IEnumerable
JScript
public class HtmlWindowCollection implements ICollection, IEnumerable

An HTML document may consist of a FRAMESET that defines multiple fixed FRAME objects, each of which contains its own HTML page. Alternatively, a document may contain a number of IFRAME objects, which can position documents arbitrarily inside of other documents. FRAME objects and IFRAME objects are represented at their top-most level by an HtmlWindowCollection, which contains elements of type HtmlWindow.

HtmlWindowCollection supports the IEnumerator interface so that it can be used in loop constructs. 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.

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.

For more information on frames, see the documentation for the Frames property.

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.

Visual Basic
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
C#
        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");
                    }
                }
            }
        }
System..::.Object
  System.Windows.Forms..::.HtmlWindowCollection
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker