System.Windows.Automation.Text.TextPatternRange.MoveEndpointByUnit C# (CSharp) Method

MoveEndpointByUnit() public method

public MoveEndpointByUnit ( TextPatternRangeEndpoint endpoint, TextUnit unit, int count ) : int
endpoint TextPatternRangeEndpoint
unit TextUnit
count int
return int
        public int MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count)
        {
            try
            {
                return this._range.MoveEndpointByUnit(
                    (UIAutomationClient.TextPatternRangeEndpoint)endpoint,
                    (UIAutomationClient.TextUnit)unit,
                    count);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Ejemplo n.º 1
0
        public TextPatternRange FindText(string text, bool backward, bool ignoreCase)
        {
            Validate.StringNeitherNullNorEmpty(parameter: text, parameterName: nameof(text));
            TextPatternRange textPatternRange = null;

            try {
                textPatternRange = new TextPatternRange(textPatternRange: IUIAutomationTextRange.FindText(text: text, backward: Convert.ToInt32(value: backward), ignoreCase: Convert.ToInt32(value: ignoreCase)));
            } catch (NotSupportedException ex) {
                var str            = GetText(maxLength: -1).Replace(oldValue: "\n", newValue: "");
                var comparisonType = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
                var count          = backward ? str.LastIndexOf(value: text, comparisonType: comparisonType) : str.IndexOf(value: text, comparisonType: comparisonType);
                if (count != -1)
                {
                    var num = count + text.Length;
                    textPatternRange = Clone();
                    textPatternRange.MoveEndpointByUnit(endpoint: TextPatternRangeEndpoint.Start, unit: TextUnit.Character, count: count);
                    textPatternRange.MoveEndpointByUnit(endpoint: TextPatternRangeEndpoint.End, unit: TextUnit.Character, count: num - str.Length);
                }
            }

            return(textPatternRange);
        }
All Usage Examples Of System.Windows.Automation.Text.TextPatternRange::MoveEndpointByUnit