Avatar of dustock
dustock
Flag for United States of America asked on

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

C#Adobe Acrobat

Avatar of undefined
Last Comment
Franck Gaspoz

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Franck Gaspoz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
dustock

ASKER
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 Gaspoz

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.
dustock

ASKER
Thanks for the help, I ended up using the System.Forms.WebBrowser component and it meets my needs!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Franck Gaspoz

You're welcome. Happy to have helped.