C# 使用按钮c滚动到Adobe Reader#
我创建了一个简单的表单,其中我使用步骤从工具箱中添加了AdobeReaderC# 使用按钮c滚动到Adobe Reader#,c#,pdf,button,scroll,C#,Pdf,Button,Scroll,我创建了一个简单的表单,其中我使用步骤从工具箱中添加了AdobeReader 在工具箱中单击鼠标右键-选择项 选择COM组件选项卡,然后出现“AdobePDF阅读器” 现在将AdobePDF阅读器控件拖放到UserControl中 我已经成功地添加了这个,打开了一个pdf文件也。现在,它自动提供了垂直滚动条,用于在pdf文档中滚动 我想实现的是,我想用一个按钮来滚动pdf,而不是使用给定的滚动条或鼠标来滚动,因此将有两个按钮,一个用于向上滚动,另一个用于向下滚动 我已经浏览了很多论坛、网页等,没
SendKeys.Send("{DOWN}");
但当我按下按钮时,焦点就消失在AdobeReader上,因此无法工作
请帮助我。。。我花了将近半天的时间搜索解决方案鉴于您只提供了一段简单的代码,我将尝试为您提供一个通用解决方案-您将需要替换指定的变量:
- 按钮名称
- 您的web应用程序名称
var pFocus = webapplication.formname.pdf_document.focus();
// or webapplication.focus(pdf_document);
同样,我只是将其作为一个理想的布局来编写,正如我所说,您需要替换列出的变量,以使其工作,并可能调整焦点代码,因为我还没有测试过它-但是,如果您插入变量名,按钮将工作,因为我已经测试过这些:
var buttonAction = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 5)");
var buttonAction_2 = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight 0)");
//button action will scroll to x co-ordinate 0(far left), y co-ordinate( 5px from bottom)
//buttonAction_2 will return you to the very top left of page, you can edit these values to mess around and try different settings.
因此,总的来说,它应该看起来有点类似于(如果您使用的是单击的方法,请在下面插入代码:
var pFocus = webapplication.formname.pdf_document.focus();
if (button.click = true)
webapplication = pFocus;
var buttonAction = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 5)");
pFocus.execute(buttonAction);
然后是按钮2
var pFocus = webapplication.formname.pdf_document.focus();
if (button_2.click = true)
webapplication = pFocus;
var buttonAction_2 = ((IJavaScriptExecutor)webapplication).ExecuteScript("window.scrollTo(0, document.body.scrollHeight 0)");
pFocus.execute(buttonAction_2);
希望这在一定程度上有所帮助。不确定您是否需要在“IJavaScriptExecutor”之后使用web应用程序名称,但请告诉我如何使用它-它可能与(IJavaScriptExecutor.ExecuteScript(“window.scrollTo(0,document.body.scrollHeight 0)”)一样工作;