다음을 통해 공유


TextPatternRange.Move(TextUnit, Int32) 메서드

정의

지정된 텍스트 단위 수만큼 텍스트 범위를 이동합니다.

public:
 int Move(System::Windows::Automation::Text::TextUnit unit, int count);
public int Move (System.Windows.Automation.Text.TextUnit unit, int count);
member this.Move : System.Windows.Automation.Text.TextUnit * int -> int
Public Function Move (unit As TextUnit, count As Integer) As Integer

매개 변수

unit
TextUnit

텍스트 단위 경계입니다.

count
Int32

이동할 텍스트 단위 수입니다. 양수 값을 사용하면 텍스트 범위가 앞으로 이동하고, 음수 값을 사용하면 텍스트 범위가 뒤로 이동하며, 0은 효과가 없습니다.

반환

실제로 이동한 단위 수입니다. 이 수는 새 텍스트 범위의 엔드포인트 중 하나가 DocumentRange 엔드포인트보다 크거나 작으면 요청된 수보다 작을 수 있습니다.

예제

/// -------------------------------------------------------------------
/// <summary>
/// Starts the target application and returns the AutomationElement 
/// obtained from the targets window handle.
/// </summary>
/// <param name="exe">
/// The target application.
/// </param>
/// <param name="filename">
/// The text file to be opened in the target application
/// </param>
/// <returns>
/// An AutomationElement representing the target application.
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement StartTarget(string exe, string filename)
{
    // Start text editor and load with a text file.
    Process p = Process.Start(exe, filename);

    // targetApp --> the root AutomationElement.
    AutomationElement targetApp =
        AutomationElement.FromHandle(p.MainWindowHandle);

    return targetApp;
}
''' -------------------------------------------------------------------
''' <summary>
''' Starts the target application and returns the AutomationElement 
''' obtained from the targets window handle.
''' </summary>
''' <param name="exe">
''' The target application.
''' </param>
''' <param name="filename">
''' The text file to be opened in the target application
''' </param>
''' <returns>
''' An AutomationElement representing the target application.
''' </returns>
''' -------------------------------------------------------------------
Private Function StartTarget( _
ByVal exe As String, ByVal filename As String) As AutomationElement
    ' Start text editor and load with a text file.
    Dim p As Process = Process.Start(exe, filename)

    ' targetApp --> the root AutomationElement.
    Dim targetApp As AutomationElement
    targetApp = AutomationElement.FromHandle(p.MainWindowHandle)

    Return targetApp
End Function
/// -------------------------------------------------------------------
/// <summary>
/// Obtain the text control of interest from the target application.
/// </summary>
/// <param name="targetApp">
/// The target application.
/// </param>
/// <returns>
/// An AutomationElement that represents a text provider..
/// </returns>
/// -------------------------------------------------------------------
private AutomationElement GetTextElement(AutomationElement targetApp)
{
    // The control type we're looking for; in this case 'Document'
    PropertyCondition cond1 =
        new PropertyCondition(
        AutomationElement.ControlTypeProperty,
        ControlType.Document);

    // The control pattern of interest; in this case 'TextPattern'.
    PropertyCondition cond2 = 
        new PropertyCondition(
        AutomationElement.IsTextPatternAvailableProperty, 
        true);

    AndCondition textCondition = new AndCondition(cond1, cond2);

    AutomationElement targetTextElement =
        targetApp.FindFirst(TreeScope.Descendants, textCondition);

    // If targetText is null then a suitable text control was not found.
    return targetTextElement;
}
''' -------------------------------------------------------------------
''' <summary>
''' Obtain the text control of interest from the target application.
''' </summary>
''' <param name="targetApp">
''' The target application.
''' </param>
''' <returns>
''' An AutomationElement. representing a text control.
''' </returns>
''' -------------------------------------------------------------------
Private Function GetTextElement(ByVal targetApp As AutomationElement) As AutomationElement
    ' The control type we're looking for; in this case 'Document'
    Dim cond1 As PropertyCondition = _
        New PropertyCondition( _
        AutomationElement.ControlTypeProperty, _
        ControlType.Document)

    ' The control pattern of interest; in this case 'TextPattern'.
    Dim cond2 As PropertyCondition = _
        New PropertyCondition( _
        AutomationElement.IsTextPatternAvailableProperty, _
        True)

    Dim textCondition As AndCondition = New AndCondition(cond1, cond2)

    Dim targetTextElement As AutomationElement = _
        targetApp.FindFirst(TreeScope.Descendants, textCondition)

    ' If targetText is null then a suitable text control was not found.
    Return targetTextElement
End Function
/// -------------------------------------------------------------------
/// <summary>
/// Moves a text range a specified number of text units. The text range 
/// is the current selection.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// <param name="textUnit">
/// The text unit value.
/// </param>
/// <param name="units">
/// The number of text units to move.
/// </param>
/// <param name="direction">
/// Direction to move the text range. Valid values are -1, 0, 1.
/// </param>
/// <returns>
/// The number of text units actually moved. This can be less than the 
/// number requested if either of the new text range endpoints is 
/// greater than or less than the DocumentRange endpoints. 
/// </returns>
/// <remarks>
/// Moving the text range does not modify the text source in any way. 
/// Only the text range starting and ending endpoints are modified.
/// </remarks>
/// -------------------------------------------------------------------
private Int32 MoveSelection(
    AutomationElement targetTextElement, 
    TextUnit textUnit,
    int units,
    int direction)
{
    TextPattern textPattern =
        targetTextElement.GetCurrentPattern(TextPattern.Pattern) 
        as TextPattern;

    if (textPattern == null)
    {
        // Target control doesn't support TextPattern.
        return -1;
    }

    TextPatternRange[] currentSelection = textPattern.GetSelection();

    if (currentSelection.Length > 1)
    {
        // For this example, we cannot move more than one text range.
        return -1;
    }

    return currentSelection[0].Move(textUnit, Math.Sign(direction) * units);
}
''' -------------------------------------------------------------------
''' <summary>
''' Moves a text range a specified number of text units.
''' </summary>
''' <param name="targetTextElement">
''' The AutomationElement that represents a text control.
''' </param>
''' <param name="textUnit">
''' The text unit value.
''' </param>
''' <param name="units">
''' The number of text units to move.
''' </param>
''' <param name="direction">
''' Direction to move the text range. Valid values are -1, 0, 1.
''' </param>
''' <returns>
''' The number of text units actually moved. This can be less than the 
''' number requested if either of the new text range endpoints is 
''' greater than or less than the DocumentRange endpoints. 
''' </returns>
''' <remarks>
''' Moving the text range does not modify the text source in any way. 
''' Only the text range starting and ending endpoints are modified.
''' </remarks>
''' -------------------------------------------------------------------
Private Function MoveSelection( _
    ByVal targetTextElement As AutomationElement, _
    ByVal textUnit As TextUnit, _
    ByVal units As Integer, _
    ByVal direction As Integer) As Integer

    Dim textPattern As TextPattern = _
    DirectCast( _
    targetTextElement.GetCurrentPattern(textPattern.Pattern), _
    TextPattern)

    If (textPattern Is Nothing) Then
        ' Target control doesn't support TextPattern.
        Return -1
    End If

    Dim currentSelection As TextPatternRange() = _
    textPattern.GetSelection()

    If (currentSelection.Length > 1) Then
        ' For this example, we cannot move more than one text range.
        Return -1
    End If

    Return currentSelection(0).Move(textUnit, Math.Sign(direction) * units)
End Function

설명

텍스트 범위의 내용을 이동해야 하는 경우 Move 메서드가 성공적으로 실행되려면 백그라운드에서 일련의 단계를 거쳐야 합니다.

  1. 텍스트 범위가 정규화됩니다. 다시 말해서, 텍스트 범위가 Start 엔드포인트에서 중복 제거 범위로 축소되어 End 엔드포인트가 불필요해집니다. 이 단계는 텍스트 범위에 걸쳐 있는 경우 모호성을 제거 하는 데 필요한 unit 경계; 예를 들어 "{The U} RL https://www.microsoft.com/ 텍스트에 포함 된" 위치 "{0}" 및 "}"는 텍스트 범위 엔드포인트입니다.

  2. 결과 범위가 DocumentRange 내에서 뒤쪽으로 옮겨져 요청된 unit 경계의 시작 부분으로 이동하게 됩니다.

  3. 범위가 요청된 DocumentRange 경계 수만큼 unit 내에서 앞이나 뒤로 이동합니다.

  4. 그런 다음, 요청된 unit 경계 하나만큼 End 엔드포인트를 이동하여 중복 제거 범위 상태이던 범위가 확장됩니다.

Move & ExpandToEnclosingUnit에서
Move() 및 ExpandToEnclosingUnit()에 따라 텍스트 범위가 조정되는 방법의 예

텍스트 컨테이너 및 포함된 개체(예: 하이퍼링크 또는 테이블 셀)의 텍스트 내용(또는 내부 텍스트)은 UI 자동화 트리의 컨트롤 뷰와 콘텐츠 뷰에서 지속적인 단일 텍스트 스트림으로 노출됩니다. 개체 경계는 무시됩니다. UI 자동화 클라이언트가 낭독, 해석 또는 분석의 목적으로 텍스트를 특정 방식으로 검색하는 경우 텍스트 내용이나 기타 포함된 개체가 있는 테이블과 같이 특수한 경우가 텍스트 범위에 있는지 확인해야 합니다. 이 호출 하 여 수행할 수 있습니다 GetChildren 가져오려고를 AutomationElement 포함 된 각 개체를 호출에 대 한 RangeFromChild 각 요소에 대 한 텍스트 범위를 얻으려면 모든 텍스트 내용이 검색 될 때까지 재귀적으로 이루어집니다.

포함된 개체에 의해 확장되는 텍스트 범위입니다.
포함된 개체가 있는 텍스트 스트림과 해당 범위의 예

Move 숨겨진 / 표시 텍스트를 따릅니다. UI 자동화 클라이언트가 확인할 수는 IsHiddenAttribute 텍스트 표시에 대 한 합니다.

Move 단위는 다음 가장 큰 TextUnit 지원 되는 경우에는 지정 된 TextUnit 컨트롤에서 지원 되지 않습니다.

가장 크고 가장 작은 단위는 순서는 아래 나열 됩니다.

참고

텍스트 범위의 텍스트의 다른 부분에만 걸쳐 대로 텍스트를 어떤 방식으로든에서 변경 되지 않습니다.

적용 대상

추가 정보