แก้ไข

แชร์ผ่าน


HtmlDocument.Forms Property

Definition

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

public:
 property System::Windows::Forms::HtmlElementCollection ^ Forms { System::Windows::Forms::HtmlElementCollection ^ get(); };
public System.Windows.Forms.HtmlElementCollection Forms { get; }
member this.Forms : System.Windows.Forms.HtmlElementCollection
Public ReadOnly Property Forms As HtmlElementCollection

Property Value

An HtmlElementCollection of the <FORM> elements within the document.

Examples

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)
        {
            form.InvokeMember("reset");
        }
    }
}
Private Sub ResetForms()
    If (Not (WebBrowser1.Document Is Nothing)) Then
        For Each FormElem As HtmlElement In WebBrowser1.Document.Forms
            FormElem.InvokeMember("reset")
        Next
    End If
End Sub

Remarks

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.

Applies to

See also