Display PDF Takes Focus and Eats Hot Key

巧了我就是萌 提交于 2019-12-12 02:48:23

问题


Used code I found on SO to use the COM based Acrobat Reader to display PDF via hosting in a WindowsFormsHost.

It displays the PDF fine. Two problems:

  • When I load the PDF the control AxAcroPDFLib.AxAcroPDF takes focus

    I want focus to remain on the prior

  • When AxAcroPDFLib.AxAcroPDF has focus it eats the Hot Key (N)

    The ALT key does not even underline the N. Even if the user selects the AxAcroPDFLib.AxAcroPDF I would like the Hot Keys to work.

I understand this is COM and Adobe in WPF and there may not be an answer. If there is a free or cheap WPF control to view PDF I would be happy to go down that path. This is for a commercial application so it has to be free (or cheap) for commercial use.

 <Button  Click="Button_Click">_Next</Button>     

 <WindowsFormsHost Name="windowsFormsHost1"  Margin="1" />
 UserControl1 UC = new UserControl1(@"C:\temp\1000001.pdf");
 this.windowsFormsHost1.Child = UC;


 public UserControl1(string filename)
 {
     InitializeComponent();
     this.axAcroPDF1.LoadFile(filename);
 }

This does display PDF. In the production application I display various PDFs based on used actions.


回答1:


No idea if it fits the needs of anyone reading this: I just found a way around my version of this problem (got a textbox for inputs and want it to regain focus after loading a pdf with AxAcroPDFLib.AxAcroPDF).

My solution was this:

        private void returnFocus(object sender, EventArgs e)
    {
        textBox.Focus();
    }

        this.textBox.LostFocus += new System.EventHandler(this.returnFocus);

Works for me!




回答2:


What Hans said. Acrobat appears to be eating key strokes and there is nothing I can do about it.




回答3:


my hacked solution for dealing with this is add a delay before enabling the panel. Obviously you want to add the minimum delay possible but too little and with the wrong file it will nick the focus again.

    System.Threading.Thread.Sleep(300)
    Panel1.Enabled = True



回答4:


This works for me:

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    If Me.AxAcroPDF1.ContainsFocus = True Then
      Me.TextBox1.Focus()
    End If
End Sub

Basically '.ContainsFocus' becomes True once the PDF document is loaded. Monitor this value in a quick timer (~200ms), and reFocus to another control if needed. Not Ideal, but it works reliably.



来源:https://stackoverflow.com/questions/8996191/display-pdf-takes-focus-and-eats-hot-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!