1 Reply Latest reply on Jun 24, 2008 12:05 PM by (Matt_Abercrombie)

    Windows Forms with ActiveX PDF viewer steals focus when LoadFile called

      I've been very frustrated with the PDF viewer. I currently have the Acrobat Reader 8.1.2 installed and I've created an extremely simple app that has a main window with two additional child windows that are owned by the main window. I've also set a timer to periodically load the same file over and over (to show the focus issue).

      My problem is that if Child1 is currently in Focus, and the timer on Child2 goes off and calls LoadFile(...), then for some reason Child2 steals the focus and comes to the front of the app.

      My Sample Visual Studio 2008 Windows Form code here:
      //Main Window code that creates Child1 and Child2 that have the ActiveX
      //component on them
      namespace PDFViewerStealingFocusIssue
      {
      public partial class MainWindow: Form
      {
      public MainWindow() {
      InitializeComponent();
      }

      private void MainWindow_Load(object sender, EventArgs e) {
      PDFViewerStealingFocusIssue.PDFViewer viewer = new PDFViewer();
      viewer.Text = "Child1";
      viewer.timer1.Interval = 4000;
      viewer.Show(this);

      viewer = new PDFViewer();
      viewer.Text = "Child2";
      viewer.timer1.Interval = 5500;
      viewer.Show(this);
      }
      }
      }

      //in my child window:
      namespace PDFViewerStealingFocusIssue
      {
      public partial class PDFViewer : Form
      {
      public PDFViewer() {
      InitializeComponent();
      }

      private void Form2_Load(object sender, EventArgs e) {
      }

      private void timer1_Tick(object sender, EventArgs e) {
      axAcroPDF1.LoadFile(@"C:\test.pdf");
      //axAcroPDF1.src = @"C:\test.pdf";
      }
      }
      }

      I'd appreciate if anyone has a workaround for stopping this annoying behavior.

      Jeff Braun (jeff-braun@comcast.net)