Displaying a pdf file from Winform

前端 未结 11 1103
醉梦人生
醉梦人生 2020-12-09 03:03

I\'m just creating a simple calculator in C# (windows form)

I\'ve created a \"User Help\" which is a pdf file, what I want is to display that pdf file if the user cl

11条回答
  •  醉梦人生
    2020-12-09 03:47

    You can reference the Adobe Reader ActiveX control and bundle it with your application.

    Simply add AcroPDF.PDF.1 to your Toolbox from the COM Components tab (right click toolbox and click Choose Items...) then drag an instance onto your Winform to have the designer create the code for you. Alternately, after adding the necessary reference you can use the following code:

    AxAcroPDFLib.AxAcroPDF pdf = new AxAcroPDFLib.AxAcroPDF();
    pdf.Dock = System.Windows.Forms.DockStyle.Fill;
    pdf.Enabled = true;
    pdf.Location = new System.Drawing.Point(0, 0);
    pdf.Name = "pdfReader";
    pdf.OcxState = ((System.Windows.Forms.AxHost.State)(new System.ComponentModel.ComponentResourceManager(typeof(ViewerWindow)).GetObject("pdfReader.OcxState")));
    pdf.TabIndex = 1;
    
    // Add pdf viewer to current form        
    this.Controls.Add(pdf);
    
    pdf.LoadFile(@"C:\MyPDF.pdf");
    pdf.setView("Fit");
    pdf.Visible = true;
    

提交回复
热议问题