Beispiel #1
0
        public int GetTextLength()
        {
            try
            {
                string txt = GetText();
                if (txt != null && NativeWindowHandle != IntPtr.Zero)
                {
                    txt = NativeTextProds.GetTextNative(NativeWindowHandle);
                }

                if (txt != null)
                {
                    int retVal = txt.Length;
                    LogText = "Length: " + retVal;
                    LogMessage();

                    return(retVal);
                }
            }
            catch (ProdOperationException err)
            {
                throw;
            }
            return(0);
        }
Beispiel #2
0
        public void Clear()
        {
            LogText = "Cleared";

            try
            {
                RegisterEvent(ValuePattern.ValueProperty);
                if (ReadOnly)
                {
                    throw new ProdOperationException("Text Control is Read Only");
                }

                if (ValuePatternHelper.SetValue(UIAElement, "") == 0)
                {
                    return;
                }


                if (NativeWindowHandle != IntPtr.Zero)
                {
                    NativeTextProds.ClearTextNative(NativeWindowHandle);
                    return;
                }

                /* If it doesn't have one, send keys, then */
                //TODO: convert ValuePatternHelper.SendKeysSetText(UIAElement, string.Empty);
            }
            catch (ProdOperationException err)
            {
                throw;
            }
        }
Beispiel #3
0
        public string GetText()
        {
            string ret = ValuePatternHelper.GetValue(UIAElement);

            if (ret == null && UIAElement.Current.NativeWindowHandle != 0)
            {
                ret = NativeTextProds.GetTextNative(NativeWindowHandle);
            }

            LogText = "Text: " + ret;
            LogMessage();

            return(ret);
        }
Beispiel #4
0
 /// <summary>
 /// Gets the text currently contained in a text area
 /// </summary>
 /// <param name="controlHandle">NativeWindowHandle to the target control</param>
 /// <returns>
 /// Text contained in text area
 /// </returns>
 /// <exception cref="ProdOperationException">Examine inner exception</exception>
 /// <remarks>
 /// This overload is invalid for WPF controls
 /// </remarks>
 public static string GetText(IntPtr controlHandle)
 {
     try
     {
         AutomationElement control = AutomationElement.FromHandle(controlHandle);
         control.GetCurrentPattern(ValuePattern.Pattern);
         string ret = ValuePatternHelper.GetValue(control);
         return(ret ?? NativeTextProds.GetTextNative(controlHandle));
     }
     catch (InvalidOperationException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ElementNotAvailableException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ArgumentException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
 }
Beispiel #5
0
        public void SetText(string text)
        {
            LogText = "Text: " + text;

            try
            {
                RegisterEvent(ValuePattern.ValueProperty);

                if (ReadOnly)
                {
                    throw new ProdOperationException("Text Control is Read Only");
                }

                if (ValuePatternHelper.SetValue(UIAElement, text) == 0)
                {
                    return;
                }


                /* If control has a handle, use native method */
                if (UIAElement.Current.NativeWindowHandle != 0)
                {
                    if (NativeTextProds.SetTextNative(NativeWindowHandle, text))
                    {
                        return;
                    }
                }

                /* If it doesn't have one, send keys, then */
                //TODO: convert   ValuePatternHelper.SendKeysSetText(UIAElement, text);
            }
            catch (ProdOperationException err)
            {
                throw;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Inserts the supplied string into the existing textBox text
        /// </summary>
        /// <param name="controlHandle">The control to be worked with</param>
        /// <param name="newText">Text to append to TextBox value</param>
        /// <param name="insertIndex">Zero based index of string to insert text into</param>
        /// <exception cref="ProdOperationException">Examine inner exception</exception>
        public static void InsertText(IntPtr controlHandle, string newText, int insertIndex)
        {
            if (GetReadOnly(controlHandle))
            {
                throw new ProdOperationException("TextBox is Read Only");
            }

            try
            {
                NativeTextProds.InsertTextNative(controlHandle, newText, insertIndex);
            }
            catch (InvalidOperationException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Set text area value
        /// </summary>
        /// <param name="controlHandle">NativeWindowHandle to the target control</param>
        /// <param name="newText">Desired text</param>
        /// <exception cref="ProdOperationException">Examine inner exception</exception>
        public static void SetText(IntPtr controlHandle, string newText)
        {
            if (GetReadOnly(controlHandle))
            {
                throw new ProdOperationException("TextBox is Read Only");
            }

            try
            {
                ValuePatternHelper.SetValue(AutomationElement.FromHandle(controlHandle), newText);
            }
            catch (InvalidOperationException)
            {
                NativeTextProds.SetTextNative(controlHandle, newText);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
 private static string NativeGetText(BaseProdControl control)
 {
     return(NativeTextProds.GetTextNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
 }
 private static void NativeSetText(BaseProdControl control, string text)
 {
     NativeTextProds.SetTextNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, text);
 }
 private static void NativeInsertText(BaseProdControl control, string newText, int index)
 {
     NativeTextProds.InsertTextNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, newText, index);
 }
        private static int NativeGetLength(BaseProdControl control)
        {
            string txt = NativeTextProds.GetTextNative((IntPtr)control.UIAElement.Current.NativeWindowHandle);

            return(txt.Length);
        }