Language

TreeWalker.GetFirstChild メソッド

定義

指定した AutomationElementの最初の子要素を取得します。

オーバーロード

Name 説明
GetFirstChild(AutomationElement)

指定した AutomationElementの最初の子要素を取得します。

GetFirstChild(AutomationElement, CacheRequest)

指定した AutomationElement の最初の子要素を取得し、プロパティとパターンをキャッシュします。

注釈

AutomationElementには、現在のビュー条件と一致しないため、要素ツリー内を移動するときに返されない追加の子要素を含めることができます。

デスクトップ上の表示されるユーザー インターフェイス (UI) 要素が変更されると、 AutomationElement ツリーの構造が変わります。 最初の子要素として返された要素が、後続のパスの最初の子として返されることは保証されません。

GetFirstChild(AutomationElement)

指定した AutomationElementの最初の子要素を取得します。

public:
 System::Windows::Automation::AutomationElement ^ GetFirstChild(System::Windows::Automation::AutomationElement ^ element);
public System.Windows.Automation.AutomationElement GetFirstChild(System.Windows.Automation.AutomationElement element);
member this.GetFirstChild : System.Windows.Automation.AutomationElement -> System.Windows.Automation.AutomationElement
Public Function GetFirstChild (element As AutomationElement) As AutomationElement

パラメーター

element
AutomationElement

最初の子を取得する要素。

戻り値

このような要素がない場合は、最初の子要素、または null 参照 (Visual Basic では Nothing)。

例

次の例 GetFirstChild 、サブツリー内の要素のツリー ビューを構築するために使用されています。

/// <summary>
/// Walks the UI Automation tree and adds the control type of each element it finds 
/// in the control view to a TreeView.
/// </summary>
/// <param name="rootElement">The root of the search on this iteration.</param>
/// <param name="treeNode">The node in the TreeView for this iteration.</param>
/// <remarks>
/// This is a recursive function that maps out the structure of the subtree beginning at the
/// UI Automation element passed in as rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
/// the desktop could take a very long time and even lead to a stack overflow.
/// </remarks>
private void WalkControlElements(AutomationElement rootElement, TreeNode treeNode)
{
    // Conditions for the basic views of the subtree (content, control, and raw) 
    // are available as fields of TreeWalker, and one of these is used in the 
    // following code.
    AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(rootElement);

    while (elementNode != null)
    {
        TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
        WalkControlElements(elementNode, childTreeNode);
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
    }
}
''' <summary>
''' Walks the UI Automation tree and adds the control type of each element it finds 
''' in the control view to a TreeView.
''' </summary>
''' <param name="rootElement">The root of the search on this iteration.</param>
''' <param name="treeNode">The node in the TreeView for this iteration.</param>
''' <remarks>
''' This is a recursive function that maps out the structure of the subtree beginning at the
''' UI Automation element passed in as rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
''' the desktop could take a very long time and even lead to a stack overflow.
''' </remarks>
Private Sub WalkControlElements(ByVal rootElement As AutomationElement, ByVal treeNode As TreeNode)
    ' Conditions for the basic views of the subtree (content, control, and raw) 
    ' are available as fields of TreeWalker, and one of these is used in the 
    ' following code.
    Dim elementNode As AutomationElement = TreeWalker.ControlViewWalker.GetFirstChild(rootElement)

    While (elementNode IsNot Nothing)
        Dim childTreeNode As TreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType)
        WalkControlElements(elementNode, childTreeNode)
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode)
    End While

End Sub

注釈

AutomationElementには、現在のビュー条件と一致しないため、要素ツリー内を移動するときに返されない追加の子要素を含めることができます。

デスクトップ上の表示されるユーザー インターフェイス (UI) 要素が変更されると、 AutomationElement ツリーの構造が変わります。 最初の子要素として返された要素が、後続のパスの最初の子として返されることは保証されません。

関連項目

適用対象

GetFirstChild(AutomationElement, CacheRequest)

指定した AutomationElement の最初の子要素を取得し、プロパティとパターンをキャッシュします。

public:
 System::Windows::Automation::AutomationElement ^ GetFirstChild(System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::CacheRequest ^ request);
public System.Windows.Automation.AutomationElement GetFirstChild(System.Windows.Automation.AutomationElement element, System.Windows.Automation.CacheRequest request);
member this.GetFirstChild : System.Windows.Automation.AutomationElement * System.Windows.Automation.CacheRequest -> System.Windows.Automation.AutomationElement
Public Function GetFirstChild (element As AutomationElement, request As CacheRequest) As AutomationElement

パラメーター

element
AutomationElement

最初の子を取得する要素。

request
CacheRequest

キャッシュに返される AutomationElement のプロパティとパターンを指定するキャッシュ要求オブジェクト。

戻り値

このような要素がない場合は、最初の子要素、または null 参照 (Visual Basic では Nothing)。

注釈

AutomationElementには、現在のビュー条件と一致しないため、要素ツリー内を移動するときに返されない追加の子要素を含めることができます。

デスクトップ上の表示されるユーザー インターフェイス (UI) 要素が変更されると、 AutomationElement ツリーの構造が変わります。 最初の子要素として返された要素が、後続のパスの最初の子として返されることは保証されません。

関連項目

適用対象