Breyta

Deila með


HtmlWindowCollection Class

Definition

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
Inheritance
HtmlWindowCollection
Implements

Examples

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

Remarks

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.

Properties

Count

Gets the number of elements in the collection.

Item[Int32]

Retrieves a frame window by supplying the frame's position in the collection.

Item[String]

Retrieves a frame window by supplying the frame's name.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Returns an enumerator that can iterate through all elements in the HtmlWindowCollection.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the elements of the collection to an Array, starting at a particular Array index.

ICollection.IsSynchronized

Gets a value indicating whether access to the collection is synchronized (thread safe).

ICollection.SyncRoot

Gets an object that can be used to synchronize access to the collection.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

See also