Export (0) Print
Expand All

HtmlDocument.Forms Property

Gets a collection of all of the <FORM> elements in the document.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElementCollection Forms { get; }

Property Value

Type: System.Windows.Forms.HtmlElementCollection
An HtmlElementCollection of the <FORM> elements within the document.

An HTML document may have one or more FORM elements with input fields for submitting data back to a server.

You can programmatically submit a FORM by obtaining its HtmlElement and calling its Submit method using the InvokeMember method.

To add a new FORM to a document, you can either create a new FORM tag as a string, and assign it to the InnerHtml property of an element previously added to the HTML DOM; or you can use the CreateElement method, set its properties using SetAttribute, and add it as a child of an existing element using AppendChild.

The following code example iterates through all of the Form elements on a Web page and clears all user input, setting the forms back to their default values.

private void ResetForms()
    if (webBrowser1.Document != null)
        foreach (HtmlElement form in webBrowser1.Document.Forms)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), 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.

© 2014 Microsoft