MultipleViewPattern.SetCurrentView(Int32) 方法

定义

设置当前的特定于控件的视图。

public:
 void SetCurrentView(int viewId);
public void SetCurrentView (int viewId);
member this.SetCurrentView : int -> unit
Public Sub SetCurrentView (viewId As Integer)

参数

viewId
Int32

特定于控件的视图标识符。

例外

viewId 不是受支持的视图集合的成员。

示例

在下面的示例中,检索可用于支持控件模式的控件的 MultipleViewPattern 视图集合。 视图标识符集合的成员随后用于修改控件的当前视图。

///--------------------------------------------------------------------
/// <summary>
/// Sets the current view of a target.
/// </summary>
/// <param name="multipleViewControl">
/// The current multiple view control.
/// </param>
/// <param name="viewID">
/// The view identifier from the supported views collection.
/// </param>
///--------------------------------------------------------------------
private void SetView(AutomationElement multipleViewControl, int viewID)
{
    if (multipleViewControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement parameter must not be null.");
    }

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

    if (multipleViewPattern != null)
    {
        try
        {
            multipleViewPattern.SetCurrentView(viewID);
        }
        // viewID is not a member of the supported views collection
        catch (ArgumentException)
        {
            // TO DO: error handling
        }
    }
}
'/--------------------------------------------------------------------
'/ <summary>
'/ Sets the current view of a target.
'/ </summary>
'/ <param name="multipleViewControl">
'/ The current multiple view control.
'/ </param>
'/ <param name="viewID">
'/ The view identifier from the supported views collection.
'/ </param>
'/--------------------------------------------------------------------
Private Sub SetView( _
ByVal multipleViewControl As AutomationElement, _
ByVal viewID As Integer)
    If multipleViewControl Is Nothing Then
        Throw New ArgumentNullException( _
        "AutomationElement parameter must not be null.")
    End If

    ' Get a MultipleViewPattern from the current control.
    Dim multipleViewPattern As MultipleViewPattern = _
    GetMultipleViewPattern(multipleViewControl)

    If Not (multipleViewPattern Is Nothing) Then
        Try
            multipleViewPattern.SetCurrentView(viewID)
        Catch exc As ArgumentException
            ' viewID is not a member of the supported views collection
            ' TO DO: error handling
        End Try
    End If
End Sub

注解

可以使用 检索 GetSupportedViews视图标识符。

特定于控件的视图标识符集合在实例之间是相同的。

适用于