【发布时间】:2019-05-18 23:05:56
【问题描述】:
我有两种形式。当单击其中一个按钮时,我想打开另一个按钮并在其中填充一个文本框。我尝试使用下面的代码,但它给出了“不支持的模式”的错误。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
string automationId = "Form1";
string newTextBoxValue = "user1";
var condition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);
var textBox = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, condition);
ValuePattern vPattern = (ValuePattern)textBox.GetCurrentPattern(ValuePattern.Pattern);
vPattern.SetValue(newTextBoxValue);
}
【问题讨论】:
-
你的问题不够清楚。这两个表单是在同一个项目中还是两个表单来自两个不同的应用程序?
-
@preciousbetine 你对歧义是正确的,但我怀疑 OP 混淆了表格和应用程序。我怀疑他想连接到另一个应用程序并在那里设置一个文本框。
标签: c# .net winforms ui-automation