Sha256: a94cb190c31113dcc9f5ab7fd2be6941e6016db970c6645ffdeaf0b10eaf8d46

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

using System.Runtime.Remoting.Services;
using System.Windows.Automation;
using System.Windows.Forms;
using RAutomation.UIA.Extensions;

namespace RAutomation.UIA.Controls
{
    public class TextControl
    {
        private readonly AutomationElement _element;

        public TextControl(AutomationElement element)
        {
            _element = element;
        }

        public string Value
        {
            get { return _element.IsValuePattern() ? TextValue : DocumentText; }
            set
            {
                if (_element.IsValuePattern())
                    TextValue = value;
                else
                    DocumentText = value;
            }
        }

        private string DocumentText
        {
            get { return _element.AsTextPattern().DocumentRange.GetText(-1); }
            set
            {
                _element.SetFocus();
                Enter("^{HOME}", "^+{END}", "{DEL}", value);
            }
        }

        private static void Enter(params string[] keys)
        {
            keys.ForEach(SendKeys.SendWait);
        }

        private string TextValue
        {
            get { return _element.AsValuePattern().Current.Value; }
            set { _element.AsValuePattern().SetValue(value);  }
        }
    }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rautomation-1.1.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-1.0.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.17.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.16.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.15.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.14.1 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.14.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.13.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.12.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs
rautomation-0.11.0 ext/UiaDll/RAutomation.UIA/Controls/TextControl.cs