C# 向webbrowser控件WPF发送命令
我有一个web浏览器控件,用于使用本机Adobe reader插件显示PDF。我想要一个按钮,可以在浏览器中调用读卡器的查找功能(即相当于按CTRL+F)C# 向webbrowser控件WPF发送命令,c#,wpf,C#,Wpf,我有一个web浏览器控件,用于使用本机Adobe reader插件显示PDF。我想要一个按钮,可以在浏览器中调用读卡器的查找功能(即相当于按CTRL+F) private void browserSearch_Click(object sender, RoutedEventArgs e) { this.browserComponent.Focusable = true; this.browserComponent.Focus(); System.Windows
private void browserSearch_Click(object sender, RoutedEventArgs e)
{
this.browserComponent.Focusable = true;
this.browserComponent.Focus();
System.Windows.Forms.SendKeys.SendWait("^f");
}
这段代码可以工作,但它只在第二次单击时显示“查找”框。
每次,您都必须在弹出“查找”框之前单击两次按钮。经过多次尝试,这对我很有用:
this.browserComponent.Focusable = true;
this.browserComponent.Focus();
System.Windows.Forms.SendKeys.SendWait("{Tab}");
this.browserComponent.Focus();
System.Windows.Forms.SendKeys.SendWait("^f");
这感觉像是一次黑客攻击,所以最好的解决方案总是受欢迎的。尝试在Focus和SendWait命令之间插入一个睡眠,可惜这没有帮助