ScrollPattern.SetScrollPercent(Double, Double) メソッド

定義

水平方向および/または垂直方向のスクロール位置を、AutomationElement 内のコンテンツ領域全域に対する割合として設定します。

public:
 void SetScrollPercent(double horizontalPercent, double verticalPercent);
public void SetScrollPercent (double horizontalPercent, double verticalPercent);
member this.SetScrollPercent : double * double -> unit
Public Sub SetScrollPercent (horizontalPercent As Double, verticalPercent As Double)

パラメーター

horizontalPercent
Double

コンテンツ領域の水平方向の全域に対する割合。 コントロールをこの方向にスクロールできない場合、NoScroll を渡す必要があります。

verticalPercent
Double

コンテンツ領域の垂直方向の全域に対する割合。 コントロールをこの方向にスクロールできない場合、NoScroll を渡す必要があります。

例外

倍精度浮動小数点型に変換できない値が渡されています。

100 より大きい、または 0 より小さい値が渡された (NoScroll と等価の -1 を除く)。 HorizontalScrollPercent および VerticalScrollPercent の値は 0% または 100% に正規化されます。

サポートされていない方向にスクロールしようとしました。

次の例では、 ScrollPattern から AutomationElement コントロール パターンを取得し、表示可能な領域をコンテンツ領域の左上の "home" 位置までスクロールするために使用します。

///--------------------------------------------------------------------
/// <summary>
/// Obtains a ScrollPattern control pattern from an 
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A ScrollPattern object.
/// </returns>
///--------------------------------------------------------------------
private ScrollPattern GetScrollPattern(
    AutomationElement targetControl)
{
    ScrollPattern scrollPattern = null;

    try
    {
        scrollPattern =
            targetControl.GetCurrentPattern(
            ScrollPattern.Pattern)
            as ScrollPattern;
    }
    // Object doesn't support the ScrollPattern control pattern
    catch (InvalidOperationException)
    {
        return null;
    }

    return scrollPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a ScrollPattern control pattern from an 
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A ScrollPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetScrollPattern( _
ByVal targetControl As AutomationElement) As ScrollPattern
    Dim scrollPattern As ScrollPattern = Nothing

    Try
        scrollPattern = DirectCast( _
        targetControl.GetCurrentPattern(scrollPattern.Pattern), _
        ScrollPattern)
    Catch
        ' Object doesn't support the ScrollPattern control pattern
        Return Nothing
    End Try

    Return scrollPattern

End Function 'GetScrollPattern
///--------------------------------------------------------------------
/// <summary>
/// Obtains a ScrollPattern control pattern from an automation 
/// element and attempts to scroll to the 'home' position.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
///--------------------------------------------------------------------
private void ScrollHome(AutomationElement targetControl)
{
    if (targetControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement argument cannot be null.");
    }

    ScrollPattern scrollPattern = GetScrollPattern(targetControl);

    if (scrollPattern == null)
    {
        return;
    }

    try
    {
        scrollPattern.SetScrollPercent(0, 0);
    }
    catch (InvalidOperationException)
    {
        // Control not able to scroll in the direction requested;
        // when scrollable property of that direction is False
        // TO DO: error handling.
    }
    catch (ArgumentOutOfRangeException)
    {
        // A value greater than 100 or less than 0 is passed in 
        // (except -1 which is equivalent to NoScroll).
        // TO DO: error handling.
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a ScrollPattern control pattern from an automation 
''' element and attempts to scroll to the top left 'home' position.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub ScrollHome(ByVal targetControl As AutomationElement) 
    If targetControl Is Nothing Then
        Throw New ArgumentNullException( _
        "AutomationElement argument cannot be null.")
    End If
    
    Dim scrollPattern As ScrollPattern = _
    GetScrollPattern(targetControl)
    
    If scrollPattern Is Nothing Then
        Return
    End If
    
    Try
        scrollPattern.SetScrollPercent(0, 0)
    Catch exc As InvalidOperationException
        ' Control not able to scroll in the direction requested;
        ' when scrollable property of that direction is False
        ' TO DO: error handling.
    Catch exc As ArgumentOutOfRangeException
        ' A value greater than 100 or less than 0 is passed in 
        ' (except -1 which is equivalent to NoScroll).
        ' TO DO: error handling.
    End Try

End Sub

注釈

このメソッドは、コントロールのコンテンツ領域が表示領域よりも大きい場合にのみ役立ちます。

NoScroll を渡すと、指定した方向にスクロールがないことを示します。

適用対象