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 을 전달해야 합니다.

예외

double로 변환할 수 없는 값인 경우

100보다 크거나 0보다 작은 값이 전달되는 경우입니다.(NoScroll에 해당하는 -1 제외) HorizontalScrollPercentVerticalScrollPercent 값은 0% 또는 100%로 정규화됩니다.

지원되지 않는 방향으로 스크롤이 시도되었습니다.

예제

다음 예제에서는 ScrollPattern 컨트롤 패턴에서 가져온는 AutomationElement 을 사용 하는 콘텐츠 영역의 위쪽 왼쪽된 '홈' 위치를 표시 가능 영역을 스크롤합니다.

///--------------------------------------------------------------------
/// <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 지정된 된 방향으로 스크롤되지 않습니다 있음을 나타냅니다.

적용 대상