通过


HtmlDocument.Forms 属性

定义

获取文档中所有 <FORM> 元素的集合。

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

属性值

文档中的<FORM>元素之一HtmlElementCollection

示例

下面的代码示例循环访问网页上的所有 Form 元素并清除所有用户输入,并将窗体设置回其默认值。

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

注解

HTML 文档可能有一个或多个 FORM 元素,其中包含用于将数据提交回服务器的输入字段。

可以通过使用InvokeMember该方法获取并调用其SubmitHtmlElement方法以编程方式提交 aFORM

若要向文档添加新FORM标记,可以创建一个新FORM标记作为字符串,并将其分配给InnerHtml以前添加到 HTML DOM 的元素的属性;或者可以使用该方法,使用CreateElement方法设置其属性SetAttribute,并将其添加为现有元素的子元素。AppendChild

适用于

另请参阅