共用方式為


MultipleViewPattern.GetViewName(Int32) 方法

定義

擷取控制項特定檢視的名稱。

public:
 System::String ^ GetViewName(int viewId);
public string GetViewName (int viewId);
member this.GetViewName : int -> string
Public Function GetViewName (viewId As Integer) As String

參數

viewId
Int32

控制項專用的檢視識別項。

傳回

當地語系化的字串,表示控制項專用的檢視名稱。

例外狀況

viewId 不是支援的檢視集合成員。

範例

在下列範例中,會從支援 MultipleViewPattern 的控制項擷取目前檢視的控制項特定名稱。

///--------------------------------------------------------------------
/// <summary>
/// Gets the name of the current view of a target.
/// </summary>
/// <param name="multipleViewControl">
/// The current multiple view control.
/// </param>
/// <returns>
/// The current view name.
/// </returns>
///--------------------------------------------------------------------
private string ViewName(AutomationElement multipleViewControl)
{
    if (multipleViewControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement parameter must not be null.");
    }

    // Get a MultipleViewPattern from the current control.
    MultipleViewPattern multipleViewPattern =
        GetMultipleViewPattern(multipleViewControl);

    if (multipleViewControl != null)
    {
        try
        {
            int viewID = 
                (int)multipleViewControl.GetCurrentPropertyValue(
                MultipleViewPattern.CurrentViewProperty);
            return multipleViewPattern.GetViewName(viewID);
        }
        catch (ArgumentException)
        {
            // TO DO: error handling
        }
    }
    return null;
}
'/--------------------------------------------------------------------
'/ <summary>
'/ Gets the name of the current view of a target.
'/ </summary>
'/ <param name="multipleViewControl">
'/ The current multiple view control.
'/ </param>
'/ <returns>
'/ The current view name.
'/ </returns>
'/--------------------------------------------------------------------
Private Function ViewName( _
ByVal multipleViewControl As AutomationElement) As String
    If multipleViewControl Is Nothing Then
        Throw New ArgumentNullException( _
        "AutomationElement parameter must not be null.")
    End If

    If Not (multipleViewControl Is Nothing) Then
        Try
            ' Get a MultipleViewPattern from the current control.
            Dim multipleViewPattern As MultipleViewPattern = _
            GetMultipleViewPattern(multipleViewControl)
            Dim viewID As Integer = _
            DirectCast(multipleViewControl.GetCurrentPropertyValue( _
            multipleViewPattern.CurrentViewProperty), Integer)
            Return multipleViewPattern.GetViewName(viewID)
        Catch exc As ArgumentException
            ' TO DO: error handling
        End Try
    End If
    Return Nothing
End Function 'ViewName

備註

您可以使用 來 GetSupportedViews 擷取檢視識別碼。

檢視識別碼的控制項特定集合在實例之間相同。

檢視名稱適用于文字轉換語音、大括弧和其他無障礙應用程式。

適用於