HtmlElementCollection.Item[] プロパティ

定義

コレクションから項目を取得します。

オーバーロード

Item[Int32]

数値インデックスを指定してコレクションから項目を取得します。

Item[String]

対応する名前を指定してコレクションから項目を取得します。

注釈

HtmlElementCollection オブジェクトは読み取り専用です。 HTML ドキュメントに要素を追加するには、次のような InsertAdjacentElement メソッドを使用します AppendChild

Item[Int32]

数値インデックスを指定してコレクションから項目を取得します。

public:
 property System::Windows::Forms::HtmlElement ^ default[int] { System::Windows::Forms::HtmlElement ^ get(int index); };
public System.Windows.Forms.HtmlElement this[int index] { get; }
member this.Item(int) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(index As Integer) As HtmlElement

パラメーター

index
Int32

コレクションから項目を取得する開始位置。

プロパティ値

HtmlElement

数値インデックスで指定した、コレクションの項目。

注釈

内の HtmlElementCollection 要素は、ソース コードの順序であるとは限りません。 つまり、要素がタグ内の DIV 最初の要素であるからといって、コレクションの BODY 最初の要素が要素になる DIV わけではありません。

適用対象

Item[String]

対応する名前を指定してコレクションから項目を取得します。

public:
 property System::Windows::Forms::HtmlElement ^ default[System::String ^] { System::Windows::Forms::HtmlElement ^ get(System::String ^ elementId); };
public System.Windows.Forms.HtmlElement this[string elementId] { get; }
member this.Item(string) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(elementId As String) As HtmlElement

パラメーター

elementId
String

要素の Name 属性または Id 属性。

プロパティ値

HtmlElement

指定された要素が見つかった場合は HtmlElement。 それ以外の場合は null

次のコード例では、オブジェクトの名前を FORM 使用してオブジェクトを検索し、プログラムによってデータをサーバーに送信します。 このコード例では、アプリケーションがコントロールwebBrowser1をホストするWebBrowser必要があります。

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

適用対象