我有一个Main.cs和一个Pdf.cs。我的Main.cs有3个按钮,每次你点击每个按钮,它导航到Pdf.cs中pdf文件的页面。例如。单击按钮1,一个新窗口将弹出,并在第1页显示pdf文件。如果单击按钮2,它将显示一个新的pdf弹出窗口第2页等。
我的问题是,是否有一种方法,pdf文件将只打开1pdf文件,每次用户单击按钮,它将只是更新/调用所选的页面?
下面是示例代码,Main.cs:
public Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ThreadStartSOP = new Thread(new ThreadStart(() => ThreadScreen(pageNumber)));
if(ThreadStartSOP.IsAlive)
{
//Update the page
}
else
{
ThreadStartSOP.SetApartmentState(ApartmentState.STA);
ThreadStartSOP.Start();
}
}
private void ThreadScreen(int pageNumber)
{
Application.Run(new pdf(pageNumber));
}Pdf.cs
public pdf(int page)
{
this.axAcroPDF1.src = @"c:\example.pdf";
this.axAcroPDF1.setCurrentPage(page);
}
public void UpdatePDFPage(int page)
{
this.axAcroPDF1.setCurrentPage(page); //Not updating..
//I tried creating delegate, then invoking the method to it
//and still no luck in updating the pdf pages..
}发布于 2016-08-26 23:19:15
我不知道Pdf.cs是表单还是其他表单;但是基本上没有引用您启动的表单;通过引用winform,您可以从主表单调用该表单上的方法。
像这样的事情应该能起作用
Pdf pdfReference;
private void dummyPage2()
{
if (pdfReference != null)
pdfReference.UpdatePDFPage(2);
}
private void ThreadScreen(int pageNumber)
{
pdfReference = new Pdf(1);
Application.Run(pdfReference);
}https://stackoverflow.com/questions/39175453
复制相似问题