TextPattern.GetSelection 메서드

정의

하나 이상의 현재 텍스트 선택 영역과 관련된 서로 분리된 텍스트 범위의 컬렉션을 검색합니다.

public:
 cli::array <System::Windows::Automation::Text::TextPatternRange ^> ^ GetSelection();
public System.Windows.Automation.Text.TextPatternRange[] GetSelection ();
member this.GetSelection : unit -> System.Windows.Automation.Text.TextPatternRange[]
Public Function GetSelection () As TextPatternRange()

반환

TextPatternRange[]

서로 분리된 텍스트 범위의 컬렉션입니다.

예외

텍스트 컨테이너에서 텍스트 선택을 지원하지 않는 경우

예제

private TextPatternRange CurrentSelection(AutomationElement target)
{
    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    // target --> The root AutomationElement.
    AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

    TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return null;
    }
    TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
    return currentSelection[0];
}
Private Function CurrentSelection(ByVal target As AutomationElement) As TextPatternRange
    ' Specify the control type we're looking for, in this case 'Document'
    Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)

    ' target --> The root AutomationElement.
    Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)

    Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)

    If (textpatternPattern Is Nothing) Then
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
        Return Nothing
    End If
    Dim currentTextSelection As TextPatternRange() = textpatternPattern.GetSelection()
    Return currentTextSelection(0)
End Function

설명

선택한 텍스트가 없는 경우 GetSelection 시스템 커서 (텍스트 삽입 지점)의 위치에서 중복 제거 텍스트 범위 (빈 범위)를 반환 합니다.

시스템 커서 (텍스트 삽입 지점)가 있는 경우 GetSelection 반환할 수 있습니다 null합니다.

참고

사용 된 SupportedTextSelection 텍스트 선택 영역이 나 텍스트 삽입 지점 위치 컨트롤에서 지원 되는 경우 테스트할 속성입니다.

적용 대상

추가 정보