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

屬性值

HtmlElementCollection

HtmlElementCollection檔中FORM > 元素的 <

範例

下列程式碼範例會逐一查看網頁上的所有 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 元素,其輸入欄位可用來將資料送回伺服器。

您可以使用 方法,以程式設計方式提交 FORMHtmlElement 並呼叫其 Submit 方法 InvokeMember

若要將新的 FORM 新增至檔,您可以建立新的 FORM 標記做為字串,並將它指派給 InnerHtml 先前新增至 HTML DOM 的專案屬性;或者您可以使用 方法,使用 CreateElement 設定其屬性 SetAttribute ,然後使用 將它新增為現有專案的子系 AppendChild

適用於

另請參閱