Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

AxAcroPDFLib throws exception when containing form is MDI child

Posted on 2010-01-08
5
Medium Priority
?
831 Views
Last Modified: 2012-05-08
I'm working on what should be a very simple project, but I'm running into a world of troubles.

I have an MDI parent form which displays a list of PDF files located on a mapped network drive. When the user double-clicks a file, an MDI child form opens to show the PDF.

The only control on the child form is of the type "Adobe Acrobat 7.0 Browser Control Type Library 1.0".

When I call the LoadFile method of the pdf viewer control, it throws this exception: First-chance exception at 0x1000847c in Foo.exe: 0xC0000005: Access violation reading location 0x00000008.

If I go into the MDI parent's code and remove the line "frmMDIChild.ParentForm = Me" and allow the pdf viewer's form to open in its own window I do not get the exception.

Doing a little googling I have found others who have the same problem but I have not found a solution anywhere.

Using a WebBrowser control to display the PDFs is not an option in this case.

Any help would be appreciated. Thanks!
0
Comment
Question by:vb9666
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26212217
(I've never worked with AxAcroPDFLib before)

Doubt this will fix the problem...

...but if you want an Mdi Child Form then change:

    frmMDIChild.ParentForm = Me

To:

    frmMDIChild.MdiParent = Me

A possible "kludge" solution would be to open up the form normally and then make it an MDI child AFTER loading the PDF?
0
 

Author Comment

by:vb9666
ID: 26212250
Idle_Mind, thanks for your comment. I am sorry, I mistakenly wrote ParentForm in my question when in the code it actually sets MdiParent.

I will try your second suggestion now.......
0
 

Author Comment

by:vb9666
ID: 26212361
I tried Idle_Mind's suggestion of setting the MdiParent property after loading the pdf. After loading the PDF, I have the program sleep for 5 seconds so that I can visually verify that the PDF was loaded. It indeed was. When the program finished sleeping and set the child form's MdiParent, the viewer no longer displayed the document but was just a white box. No exceptions were thrown.

frmR.Show()
frmR.LoadPDF()
frmR.Refresh()
System.Threading.Thread.Sleep(5000)
frmR.MdiParent = Me
frmR.Refresh()
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 26212574
Not sure if there is a "proper" solution to this one...  =\

Was able to display it as a "pseudo mdi child" like this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using ofd As New OpenFileDialog
            ofd.Filter = "PDF Files (*.pdf)|*.pdf"
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim f1 As New Form1
                f1.AxAcroPDF1.LoadFile(ofd.FileName)
                f1.TopLevel = False ' <-- can't work without this
                Me.Controls.Add(f1)
                f1.Show()
            End If
        End Using
    End Sub

It's not a TRUE MdiChild though...not sure how this would affect your current app!
PDF-Viewer-in-a-Pseudo-MdiChild.JPG
0
 

Author Closing Comment

by:vb9666
ID: 31674677
More of a workaround than a solution, but it works for me! Thanks!!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question