gpt4 book ai didi

c# - .NET 自动化 ControlType.Document : how to manipulate text?

转载 作者:行者123 更新时间:2023-11-30 17:17:13 25 4
gpt4 key购买 nike

如何使用 System.Windows.Automation 将文本设置到 ControlType.Document 元素中?

ValuePattern 不适用于 Document ControlType,TextPattern 不允许设置新值。

这不起作用:

automationElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern)
.setValue(value);

最佳答案

我用这个方法发现了一个丑陋的方法:

private void InsertTextIntoAutomationElement(AutomationElement element, string value) {

object valuePattern = null;

if (!element.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern)) {
element.SetFocus();
Thread.Sleep(100);

SendKeys.SendWait("^{HOME}"); // Move to start of control
SendKeys.SendWait("^+{END}"); // Select everything
SendKeys.SendWait("{DEL}"); // Delete selection
SendKeys.SendWait(value);
} else{
element.SetFocus();
((ValuePattern)valuePattern).SetValue(value);
}
}

关于c# - .NET 自动化 ControlType.Document : how to manipulate text?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6708022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com