HtmlElementCollection Class
.NET Framework 4.5
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Defines a collection of HtmlElement objects.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The HtmlElementCollection type exposes the following members.
| Name | Description | |
|---|---|---|
|
Count | Gets the number of elements in the collection. |
|
Item[Int32] | Gets an item from the collection by specifying its numerical index. |
|
Item[String] | Gets an item from the collection by specifying its name. |
| Name | Description | |
|---|---|---|
|
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
|
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
|
GetElementsByName | Gets a collection of elements by their name. |
|
GetEnumerator | Returns an enumerator that iterates through a collection. |
|
GetHashCode | Serves as a hash function for a particular type. (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.) |
| Name | Description | |
|---|---|---|
|
AsParallel | Enables parallelization of a query. (Defined by ParallelEnumerable.) |
|
AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) |
|
Cast<TResult> | Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) |
|
OfType<TResult> | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
| Name | Description | |
|---|---|---|
|
ICollection.CopyTo | Infrastructure. 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 HtmlElementCollection is synchronized (thread safe). |
|
ICollection.SyncRoot | Infrastructure. Gets an object that can be used to synchronize access to the collection. |
The following code example uses HtmlElementCollection objects to print out a textual representation of the Document Object Model (DOM) of a page.
private void PrintDomBegin() { if (webBrowser1.Document != null) { HtmlElementCollection elemColl = null; HtmlDocument doc = webBrowser1.Document; if (doc != null) { elemColl = doc.GetElementsByTagName("HTML"); String str = PrintDom(elemColl, new System.Text.StringBuilder(), 0); webBrowser1.DocumentText = str; } } } private string PrintDom(HtmlElementCollection elemColl, System.Text.StringBuilder returnStr, Int32 depth) { System.Text.StringBuilder str = new System.Text.StringBuilder(); foreach (HtmlElement elem in elemColl) { string elemName; elemName = elem.GetAttribute("ID"); if (elemName == null || elemName.Length == 0) { elemName = elem.GetAttribute("name"); if (elemName == null || elemName.Length == 0) { elemName = "<no name>"; } } str.Append(' ', depth * 4); str.Append(elemName + ": " + elem.TagName + "(Level " + depth + ")"); returnStr.AppendLine(str.ToString()); if (elem.CanHaveChildren) { PrintDom(elem.Children, returnStr, depth + 1); } str.Remove(0, str.Length); } return(returnStr.ToString()); }
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.