代码之家  ›  专栏  ›  技术社区  ›  SharpAffair

.NET以编程方式在ActiveX控件中定位文本框,修改其文本并提交

  •  0
  • SharpAffair  · 技术社区  · 16 年前

    我有一个带有工具栏的ActiveX控件(Adobe PDF Reader)。此控件不公开通过工具栏提供的某些功能(主要是搜索功能)。我正在寻找一种方法,以编程方式在工具栏上定位搜索字段,输入文本并调用搜索(相当于在此字段中按enter键)。 最准确的方法是什么?找到了一个基于系统.Windows.Automation命名空间,但无法使其正常工作。

    谢谢。

    以下是我尝试的代码:

    Dim pdfElement As AutomationElement = AutomationElement.FromHandle(AxAcroPDF1.Handle)
    Dim condition As New AndCondition(New OrCondition(New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)), New PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, True))
    Dim ac As AutomationElementCollection = pdfElement.FindAll(TreeScope.Descendants, condition)
    
    For Each element As AutomationElement In ac
    
        If element.Current.Name = "Find" Then
            element.SetFocus()
            SendKeys.Send("TESTSEARCH")
        End If
    
    Next
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Hans Passant    16 年前

    和你上一个问题的答案一样。零售自动化接口具有FindText()方法。我已经给了你API文档的链接。