h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

PDFViewer in C#.Net

InitializeComponent
namespace TestEasyCon
{
    partial class PDFViewer
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PDFViewer));
            this.panel1 = new System.Windows.Forms.Panel();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
            this.tsmClose = new System.Windows.Forms.ToolStripMenuItem();
            this.tsmExit = new System.Windows.Forms.ToolStripMenuItem();
            this.panel1.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.axAcroPDF1)).BeginInit();
            this.SuspendLayout();
            //
            // panel1
            //
            this.panel1.Controls.Add(this.axAcroPDF1);
            this.panel1.Controls.Add(this.menuStrip1);
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(600, 680);
            this.panel1.TabIndex = 0;
            //
            // menuStrip1
            //
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsmClose,
            this.tsmExit});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(600, 24);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            //
            // axAcroPDF1
            //
            this.axAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.axAcroPDF1.Enabled = true;
            this.axAcroPDF1.Location = new System.Drawing.Point(0, 24);
            this.axAcroPDF1.Name = "axAcroPDF1";
            this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));
            this.axAcroPDF1.Size = new System.Drawing.Size(600, 656);
            this.axAcroPDF1.TabIndex = 1;
            //
            // tsmClose
            //
            this.tsmClose.AutoToolTip = true;
            this.tsmClose.Image = ((System.Drawing.Image)(resources.GetObject("tsmClose.Image")));
            this.tsmClose.Name = "tsmClose";
            this.tsmClose.Size = new System.Drawing.Size(61, 20);
            this.tsmClose.Text = "Close";
            this.tsmClose.ToolTipText = "Close PDF File";
            //
            // tsmExit
            //
            this.tsmExit.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
            this.tsmExit.AutoToolTip = true;
            this.tsmExit.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tsmExit.Image = ((System.Drawing.Image)(resources.GetObject("tsmExit.Image")));
            this.tsmExit.Name = "tsmExit";
            this.tsmExit.Size = new System.Drawing.Size(28, 20);
            this.tsmExit.ToolTipText = "Close PDF File";
            //
            // PDFViewer
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.panel1);
            this.Name = "PDFViewer";
            this.Size = new System.Drawing.Size(603, 684);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.axAcroPDF1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
        private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem tsmClose;
        private System.Windows.Forms.ToolStripMenuItem tsmExit;
    }
}
Code Behind
using System;
using System.Windows.Forms;

namespace TestEasyCon
{
    public partial class PDFViewer : UserControl
    {
        public PDFViewer()
        {
            InitializeComponent();
            tsmClose.Click += new EventHandler(CloseButtonClicked);
            tsmExit.Click += new EventHandler(CloseButtonClicked);
        }

        #region Declaration
        public delegate void CloseButtonEventHandler(object sender, EventArgs e);
        public event CloseButtonEventHandler ClickCloseButton;
        #endregion

        #region Functions
        private void CloseButtonClicked(object sender, EventArgs e)
        {
            if (ClickCloseButton != null)
                ClickCloseButton(this, e);
        }
        /// <summary>
        /// Display PDf File
        /// </summary>
        /// <param name="filePath">Pass File Path</param>
        public void DisplayPDFFile(string filePath)
        {
            axAcroPDF1.src = filePath;
            axAcroPDF1.setShowToolbar(true);
            axAcroPDF1.Show();
        }
        #endregion

    }
}

No comments:

Post a Comment