TextPatternRange.MoveEndpointByRange 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将文本范围的一个端点移动到第二个文本范围的指定端点。
public:
void MoveEndpointByRange(System::Windows::Automation::Text::TextPatternRangeEndpoint endpoint, System::Windows::Automation::Text::TextPatternRange ^ targetRange, System::Windows::Automation::Text::TextPatternRangeEndpoint targetEndpoint);
public void MoveEndpointByRange (System.Windows.Automation.Text.TextPatternRangeEndpoint endpoint, System.Windows.Automation.Text.TextPatternRange targetRange, System.Windows.Automation.Text.TextPatternRangeEndpoint targetEndpoint);
member this.MoveEndpointByRange : System.Windows.Automation.Text.TextPatternRangeEndpoint * System.Windows.Automation.Text.TextPatternRange * System.Windows.Automation.Text.TextPatternRangeEndpoint -> unit
Public Sub MoveEndpointByRange (endpoint As TextPatternRangeEndpoint, targetRange As TextPatternRange, targetEndpoint As TextPatternRangeEndpoint)
参数
- endpoint
- TextPatternRangeEndpoint
要移动的端点。
- targetRange
- TextPatternRange
同一文本提供程序中的另一个范围。
- targetEndpoint
- TextPatternRangeEndpoint
另一个范围中的端点。
示例
private void MoveEndpointByRangeFromSelection(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;
}
TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
TextPatternRange[] currentVisibleRanges = textpatternPattern.GetVisibleRanges();
currentSelection[0].MoveEndpointByRange(
TextPatternRangeEndpoint.Start,
currentVisibleRanges[0],
TextPatternRangeEndpoint.Start);
}
Private Sub MoveEndpointByRangeFromSelection(ByVal target As AutomationElement)
' 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
End If
Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
Dim currentVisibleRanges As TextPatternRange() = textpatternPattern.GetVisibleRanges()
currentSelection(0).MoveEndpointByRange(TextPatternRangeEndpoint.Start, _
currentVisibleRanges(0), _
TextPatternRangeEndpoint.Start)
End Sub
注解
如果移动的终结点跨越同一文本范围的另一终结点,则另一终结点也会移动,导致范围退化,并确保终结点 (Start 的正确顺序始终小于或等于 End) 。