TextPatternRange.Move(TextUnit, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
텍스트 범위를 지정된 수의 텍스트 단위로 이동합니다.
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 메서드가 성공적으로 실행되도록 하기 위해 백그라운드에서 여러 단계가 수행됩니다.
텍스트 범위가 정규화됩니다. 즉, 텍스트 범위가 Start 엔드포인트에서 단일화된 범위로 축소되어 End 엔드포인트가 불필요하게 됩니다. 이 단계는 텍스트 범위가 경계에 걸쳐
unit있는 상황에서 모호성을 제거하는 데 필요합니다. 예를 들어 "{{" 및 "}"이 텍스트 범위 엔드포인트인 경우 "{U}RL https://www.microsoft.com/ 이 텍스트에 포함됩니다."결과 범위는 요청된 DocumentRange 경계의 시작 부분으로
unit뒤로 이동합니다.DocumentRange에서 요청된 수의
unit경계를 따라 범위를 앞으로 또는 뒤로 이동합니다.요청된 End 경계에 따라
unit엔드포인트를 이동하여 퇴행성 범위 상태에서 범위를 확장합니다.
Move() 및 ExpandToEnclosingUnit()에 대해 텍스트 범위를 조정하는 방법의 예
텍스트 컨테이너 및 포함된 개체(예: 하이퍼링크 또는 테이블 셀)의 텍스트 내용(또는 내부 텍스트)은 UI 자동화 트리의 컨트롤 뷰와 콘텐츠 뷰에서 지속적인 단일 텍스트 스트림으로 노출됩니다. 개체 경계는 무시됩니다. UI 자동화 클라이언트가 어떤 방식으로든 암송, 해석 또는 분석 목적으로 텍스트를 검색하는 경우 텍스트 내용이 있는 테이블이나 기타 포함된 개체와 같은 특수한 경우 텍스트 범위를 확인해야 합니다. 이 작업은 포함된 각 개체에 대해 가져오기 위해 GetChildren 호출 AutomationElement 한 다음 각 요소에 대한 텍스트 범위를 가져오기 위해 호출 RangeFromChild 하여 수행할 수 있습니다. 이 작업은 모든 텍스트 콘텐츠를 검색할 때까지 재귀적으로 수행됩니다.
포함된 개체 및 범위 범위가 있는 텍스트 스트림의 예
Move 는 숨겨진 텍스트와 표시되는 텍스트를 모두 적용합니다. UI 자동화 클라이언트는 IsHiddenAttribute 텍스트 표시 여부를 확인할 수 있습니다.
Move지정된 컨트롤에서 지원되지 않는 경우 TextUnit 지원되는 다음으로 가장 TextUnit 큰 값으로 지연합니다.
가장 작은 단위에서 가장 큰 단위로 순서가 아래에 나열되어 있습니다.
메모
텍스트 범위가 텍스트의 다른 부분에 걸쳐 있기 때문에 텍스트는 어떤 방식으로도 변경되지 않습니다.