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; } }
/// <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 void NativeSetText(BaseProdControl control, string text) { NativeTextProds.SetTextNative((IntPtr)control.UIAElement.Current.NativeWindowHandle, text); }