Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF Document does not display when creating control dynamically

Tags:

c#

pdf

I have an application that I want to display multiple PDF documents. If I define the control at design time I can load a document and display it, but when I dynamically create the control during run time I cannot get it to display. The document is being displayed in a tab.

Here is my code...

AxAcroPDF newPDF = new AxAcroPDF();
newPDF.CreateControl();
newPDF.Width = selectedTab.Width;
newPDF.Height = selectedTab.Height;
newPDF.LoadFile(filePath);

selectedTab.Controls.Add(newPDF);
newPDF.Show();
newPDF.Visible = true;

How do I get the PDF to display?

like image 427
Gary Avatar asked Apr 20 '15 19:04

Gary


2 Answers

This is what worked for me...

AxAcroPDF newPDF = new AxAcroPDF();
selectedTab.Controls.Add(newPDF);

newPDF.CreateControl();
newPDF.Width = selectedTab.Width;
newPDF.Height = selectedTab.Height;

newPDF.LoadFile(filePath);
newPDF.Show();

For some reason it doesn't like the PDF control being added to the tab after the CreateControl() method is executed.

like image 158
Gary Avatar answered Oct 15 '22 05:10

Gary


Don't use Width and Height but ActualWidth and ActualHeight from the SelectedTab. Under certain circumstances the non actuals may report zero sizes.

Otherwise hard code height and width to see if that provides an insight as to whether it is showing up, but hidden.

like image 2
ΩmegaMan Avatar answered Oct 15 '22 04:10

ΩmegaMan