-1

In my form application i added an adobe reader control to show pdf files IN my application. I have a split panel, so on the left is a tree view with directories and files. And on the right side i have the adobe reader control. Works good.

But i want to implement some key-events while the focus is on the adobe reader control. I search around the whole day withound find a solution that works.

I also tried to override the ProcessCmdKey-Event, but it didn't work too. The Event isn't called, when the focus is on the adobe reader control. The Event is calld, if the focus are on the form or at the tree view. No error was displayd or in the console. Also tested with an breakpoint.

So, is there something you know and I don't? Your suggestions are very welcome. Thanks.

codeslave
  • 13
  • 6
  • 1
    Can you be more clear about, ProcessCmdKey-Event didn't work, what happend, did an error occur or didn't the Event get called? Could you put a breakpoint inside to test? – Max Nov 18 '13 at 15:44
  • 1
    Adobe Reader is evil. It embeds the window of another process inside your form. That window is a black hole for keystrokes, only the Adobe process can see them. The only sane advice is to not use evil software. – Hans Passant Nov 18 '13 at 16:06
  • Is there a good alternative for showing PDF files within a form and without using adobe reader? – codeslave Nov 18 '13 at 16:09

1 Answers1

0

Just tested following override of the ProcessCmdKey method. It works for me, could you try following code?

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)
{
      if (keyData == (Keys.Control | Keys.OemQuestion))
      {
                MessageBox.Show("Shortcut Keys Work!", "Yay!");
                //Code executes when CTRL + ? button are pressed.
                //Change keys to your needs.
                return true;
      }
      return base.ProcessCmdKey(ref msg, keyData);
}

I'm not sure what key shortcuts you want to handle, but above code handles CTRL + QuestionMark, IntelliSense will help you with more options, when putting a period behind Keys.

Max
  • 12,622
  • 16
  • 73
  • 101
  • thanks for your example. tested: did not work. (maybe) dumb question, but only to get sure (i'm new to visual studio and c#): with "override the ... method" you mean: copy this method into my Form.cs class, as method, right? – codeslave Nov 18 '13 at 15:44
  • What did not work? Error, or didn't it get called? Have you tried setting a breakpoint? – Max Nov 18 '13 at 15:45
  • yes, i set a breakpoint. without show a pdf the method is called and the code executed. but at the moment the focus is the adobe reader control nothing happens, the method aren't called (without an error message). – codeslave Nov 18 '13 at 15:48
  • Which PDF control do you use? – Max Nov 18 '13 at 15:51
  • I use the "Adobe PDF Reader" control from the adobe installation under ...Program Files(x86)\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll In the form-property-box is calld AxAcroPDFLib.AxAcroPDF. – codeslave Nov 18 '13 at 15:54
  • Is there a keyDown event available for the control? Click the control, click the lightning icon, check KeyDown events. – Max Nov 18 '13 at 15:57
  • I tried it myself, dragging the control on a winform, you could try to use the PreviewKeyDown event. – Max Nov 18 '13 at 16:03
  • and it worked? I've created one from the scratch, didn't work. i recorded it as video, you can find it here: [link](http://www.youtube.com/watch?v=V0Vo2p2jz9M) – codeslave Nov 19 '13 at 10:10