Condividi tramite


HtmlElementCollection.GetElementsByName(String) Metodo

Definizione

Ottiene una raccolta di elementi in base al 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

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

Esempio

Nell'esempio di codice seguente viene trovato un FORM oggetto usando il relativo nome e i relativi dati vengono inviati al server a livello di codice. L'esempio di codice richiede che l'applicazione ospiti 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 oggetto deve essere univoca HtmlElement , più elementi possono utilizzare la stessa Name proprietà.

Si applica a