ITextRangeProvider.MoveEndpointByUnit Method (TextPatternRangeEndpoint, TextUnit, Int32)


Moves one endpoint of the text range the specified number of text units within the document range.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

int MoveEndpointByUnit(
	TextPatternRangeEndpoint endpoint,
	TextUnit unit,
	int count


Type: System.Windows.Automation.Text.TextPatternRangeEndpoint

The endpoint to move.

Type: System.Windows.Automation.Text.TextUnit

The textual unit for moving.

Type: System.Int32

The number of units to move. A positive value moves the endpoint forward. A negative value moves backward. A value of 0 has no effect.

Return Value

Type: System.Int32

The number of units actually moved, which can be less than the number requested if moving the endpoint runs into the beginning or end of the document.

When it is necessary to traverse the content of a text range, a series of steps are involved behind the scenes in order for the Move method to execute successfully.

  1. The text range is normalized; that is, the text range is collapsed to a degenerate range at the Start endpoint, which makes the End endpoint superfluous. This step is necessary to remove ambiguity in situations where a text range spans unit boundaries; for example, "{The U}RL is embedded in text" where "{" and "}" are the text range endpoints.

  2. The resulting range is moved backward in the DocumentRange to the beginning of the requested unit boundary.

  3. The range is then expanded from a degenerate range state by moving the End endpoint by one requested unit boundary.


Range adjustments by Move & ExpandToEnclosingUnit

Examples of how a text range is adjusted for Move() and ExpandToEnclosingUnit()

MoveEndpointByUnit defers to the next largest TextUnit supported if the given TextUnit is not supported by the control.

The order, from smallest unit to largest, is listed below.

.NET Framework
Available since 3.0
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Return to top