How to: Add a PDF Viewer to the WinForms Application via Code
- 2 minutes to read
This example describes how to programmatically add a PDF Viewer to a Windows Forms application.
To add a PDF Viewer to the Windows Forms application at runtime, do the following.
- Run Microsoft® Visual Studio® 2012, 2013, 2015 or 2017.
- Create a new Windows Forms application project or open an existing one.
Open the Solution Explorer, right-click References and choose Add Reference… to add references to the PDF Viewer libraries.
In the Extensions tab, select the DevExpress.XtraPdfViewer.v18.2, DevExpress.Pdf.v18.2.Core, DevExpress.Data.v18.2, DevExpress.Utils.v18.2 assemblies and click OK.
Write the following (or similar) code:
using DevExpress.XtraPdfViewer; using System; using System.Windows.Forms; namespace CreatePdfViewer { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Create a PDF viewer. PdfViewer viewer = new PdfViewer(); // Specify the viewer position on the form. viewer.Dock = DockStyle.Fill; // Add the PDF viewer to the window. this.Controls.Add(viewer); } } }
Run the application to see the result.
See Also