Avatar of dustock
dustockFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Franck Gaspoz
Franck Gaspoz
Flag of France image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dustock
dustock
Flag of United States of America image

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!
Avatar of Franck Gaspoz
Franck Gaspoz
Flag of France image

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.
Avatar of dustock
dustock
Flag of United States of America image

ASKER

Thanks for the help, I ended up using the System.Forms.WebBrowser component and it meets my needs!
Avatar of Franck Gaspoz
Franck Gaspoz
Flag of France image

You're welcome. Happy to have helped.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo