Display multiple PDF's in windows forms tab control

I am working on a program that will eventually dynamically create tabs to display pdf files, word documents and text files.  To start I am just using an OpenFileDialog to point to a pdf to create a tab and open the file.  This is working for 1 pdf, with one small issue, I have to click on the PDF control in order for the pdf to display, otherwise its just a grey screen.  My bigger problem is when I try to add a second file to the mix.  When I click the button again to add another file the code executes until it reaches "PDFFile.LoadFile(strFileName);".  At that point I get an error, Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.  I've tried to find a solution but the one I keep seeing is I need to put in CreateControl(), which I am already doing.  Has anyone tried to do anything like this and had success?

            try
            {
                TabPage page = new TabPage();

                tabMain.Controls.Add(page);
                page.Text = strTabName;

                switch (strControlType)
                {
                    case "pdf":
                        AxAcroPDF PDFFile = new AxAcroPDF();                        
                        page.Controls.Add(PDFFile);
                        PDFFile.CreateControl();
                        PDFFile.Dock = DockStyle.Fill;
                        PDFFile.LoadFile(strFileName);
                        break;
                    case "doc":
                    case "docx":
                        break;
                    case "txt":
                        break;
                    default:
                        break;
                }                
            }
            catch(Exception ex)
            {
                var message = ex.Message.ToString();
                MessageBox.Show(message);
            }

Open in new window

LVL 9
dustockAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Franck GaspozSoftware Architect, Technical ExpertCommented:
you could try to use property src of the control as a workaround :
PDFFile.src = "c:\mypdf.pdf"
in an other way, why don't you consider using the web browser component AxSHDocVW.AxWebBrowser for .net which embed IE ? this one can open and display any type of document ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dustockAuthor Commented:
I got the same error when trying to use the src property.

I will look into the AxSHDocVW.AxWebBrowser to see if that meets my needs.

Thank you!
Franck GaspozSoftware Architect, Technical ExpertCommented:
you're welcome. Hope this will help you.
you will see that this component is really surprising because it works simply as a browser, and also if wished it let you access to the internal document model of ie ( objects, events, ... ). It is now replacing the old ActiveX object provided by Microsoft (1 version of the object for each version of ie), this new one can make running several ie motors.
dustockAuthor Commented:
Thanks for the help, I ended up using the System.Forms.WebBrowser component and it meets my needs!
Franck GaspozSoftware Architect, Technical ExpertCommented:
You're welcome. Happy to have helped.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.