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

屬性值

String

使用者介面的名稱, (UI) 元素。The name of the 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

備註

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

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

適用於