HtmlElementCollection.GetElementsByName(String) Metodo

Definizione

Ottiene un insieme di elementi mediante il relativo nome.

public:
 System::Windows::Forms::HtmlElementCollection ^ GetElementsByName(System::String ^ name);
public System.Windows.Forms.HtmlElementCollection GetElementsByName (string name);
member this.GetElementsByName : string -> System.Windows.Forms.HtmlElementCollection
Public Function GetElementsByName (name As String) As HtmlElementCollection

Parametri

name
String

Nome o ID dell'elemento.

Restituisce

HtmlElementCollection

Oggetto HtmlElementCollection che contiene gli elementi la cui proprietà Name corrisponde a name.

Esempio

L'esempio di codice seguente trova un FORM oggetto usando il nome e invia i dati al server a livello di codice. L'esempio di codice richiede che l'applicazione ospita un WebBrowser controllo denominato webBrowser1.

private void SubmitForm(String formName)
{
    HtmlElementCollection elems = null;
    HtmlElement elem = null;

    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        elems = doc.All.GetElementsByName(formName);
        if (elems != null && elems.Count > 0)
        {
            elem = elems[0];
            if (elem.TagName.Equals("FORM"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}
Private Sub SubmitForm(ByVal FormName As String)
    Dim Elems As HtmlElementCollection
    Dim Elem As HtmlElement

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Elems = .All.GetElementsByName(FormName)
            If (Not Elems Is Nothing And Elems.Count > 0) Then
                Elem = Elems(0)
                If (Elem.TagName.Equals("FORM")) Then
                    Elem.InvokeMember("Submit")
                End If
            End If
        End With
    End If
End Sub

Commenti

Anche se la Id proprietà di un HtmlElement oggetto deve essere univoca, più elementi possono usare la stessa Name proprietà.

Si applica a