本文整理汇总了C#中System.Windows.Automation.Text.TextPatternRange.Move方法的典型用法代码示例。如果您正苦于以下问题:C# TextPatternRange.Move方法的具体用法?C# TextPatternRange.Move怎么用?C# TextPatternRange.Move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了TextPatternRange.Move方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartTarget
/// -------------------------------------------------------------------
/// <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;
}
示例2: GetTextElement
/// -------------------------------------------------------------------
/// <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;
}
示例3: MoveSelection
/// -------------------------------------------------------------------
/// <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);
}