我有一个带有工具栏的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