AutomationElement.AutomationElementInformation.Name 屬性

定義

取得項目的名稱。Gets the name of the element.

public:
 property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String

屬性值

使用者介面 (UI)user interface (UI) 項目的名稱。The name of the 使用者介面 (UI)user interface (UI) element.

範例

下列範例顯示如何Name抓取屬性。The following example shows how the Name property is retrieved.

/// <summary>
/// Handles ElementSelected events by showing a message.
/// </summary>
/// <param name="src">Object that raised the event; in this case, a list item.</param>
/// <param name="e">Event arguments.</param>
private void OnSelect(object src, AutomationEventArgs e)
{
    // Get the name of the item, which is equivalent to its text.
    AutomationElement element = src as AutomationElement;
    if (element != null)
    {
        Console.WriteLine(element.Current.Name + " was selected.");
    }
}
''' <summary>
''' Handles ElementSelected events by showing a message.
''' </summary>
''' <param name="src">Object that raised the event; in this case, a list item.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnSelect(ByVal src As Object, ByVal e As AutomationEventArgs)
    ' Get the name of the item, which is equivalent to its text.
    Dim element As AutomationElement = DirectCast(src, AutomationElement)
    If (element IsNot Nothing) Then
        Console.WriteLine(element.Current.Name + " was selected.")
    End If

End Sub

備註

當元素不支援UI 自動化UI Automation 屬性時,專案的名稱可以用來尋找元素樹狀結構中的專案。AutomationIdThe name of an element can be used to find the element in the UI 自動化UI Automation element tree when the AutomationId property is not supported on the element.

如需詳細資訊,請參閱NamePropertyFor more information, see NameProperty.

適用於