共用方式為


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 擷取檢視識別碼。

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

適用於