using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UdPdfWin
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //mnuOpenResource_Click(sender, e);
        }

        #region 文件菜单

        private void mnuOpenFile_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == this.openFileDialog.ShowDialog(this))
            {
                //文件先读取到内存中然后加载
                //using(System.IO.FileStream fs = new System.IO.FileStream(this.openFileDialog.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read))
                //{
                //    byte [] buf = new byte[fs.Length];
                //    fs.Read(buf,0,(int)fs.Length);
                //    this.axUdPdf.LoadFromData(buf);
                //}
                
                //直接从文件加载
                this.axUdPdf.LoadFromFile(this.openFileDialog.FileName);
                this.mnuBookmark.Enabled = this.axUdPdf.HasBookmark;
            }
        }

        private void mnuOpenResource_Click(object sender, EventArgs e)
        {
            string assembleName = this.GetType().Assembly.GetName().Name;
            System.IO.Stream stream =
                this.GetType().Assembly.GetManifestResourceStream(assembleName + ".PDFSample.pdf");

            byte[] buf = new byte[(int)stream.Length];
            stream.Read(buf, 0, buf.Length);
            stream.Close();

            this.axUdPdf.LoadFromData(buf);
            this.mnuBookmark.Enabled = this.axUdPdf.HasBookmark;
        }

        private void mnuPrint_Click(object sender, EventArgs e)
        {
            this.axUdPdf.Print();
        }

        private void mnuClose_Click(object sender, EventArgs e)
        {
            this.axUdPdf.Close();
        }

        private void mnuExit_Click(object sender, EventArgs e)
        {
            this.Close();
            this.mnuBookmark.Enabled = true;
        }

        #endregion

        #region 查看菜单

        private void mnuZoomFitWidth_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ZoomFitWidth();
        }

        private void mnuZoomFitPage_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ZoomFitPage();
        }

        private void mnuZoomActual_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ZoomActual();
        }

        private void mnuZoomIn_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ZoomIn();
        }

        private void mnuZoomOut_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ZoomOut();
        }

        private void mnuRotateLeft_Click(object sender, EventArgs e)
        {
            this.axUdPdf.RotateLeft();
        }

        private void mnuRotateRight_Click(object sender, EventArgs e)
        {
            this.axUdPdf.RotateRight();
        }


        private void mnuGotoFirstPage_Click(object sender, EventArgs e)
        {
            this.axUdPdf.GoToFirstPage();
        }

        private void mnuGotoPrevPage_Click(object sender, EventArgs e)
        {
            this.axUdPdf.GoToPrevPage();
        }

        private void mnuGotoNextPage_Click(object sender, EventArgs e)
        {
            this.axUdPdf.GoToNextPage();
        }

        private void mnuGotoLastPage_Click(object sender, EventArgs e)
        {
            this.axUdPdf.GoToLastPage();
        }

        private void mnuToolBar_Click(object sender, EventArgs e)
        {
            this.mnuToolBar.Checked = !this.mnuToolBar.Checked;
            this.axUdPdf.ToolbarVisible = this.mnuToolBar.Checked;
        }


        private void mnuBookmark_Click(object sender, EventArgs e)
        {
            this.mnuBookmark.Checked = !this.mnuBookmark.Checked;
            this.axUdPdf.BookmarkVisible = this.mnuBookmark.Checked;
        }

        private void mnuFullScreen_Click(object sender, EventArgs e)
        {
            this.axUdPdf.ToggleFullScreen();
        }

        #endregion

        #region 安全菜单

        private void mnuAllowCopy_Click(object sender, EventArgs e)
        {
            this.mnuAllowCopy.Checked = !this.mnuAllowCopy.Checked;
            this.axUdPdf.EnableCopy = this.mnuAllowCopy.Checked;
        }

        private void mnuAllowPrint_Click(object sender, EventArgs e)
        {
            this.mnuAllowPrint.Checked = !this.mnuAllowPrint.Checked;
            this.mnuPrint.Enabled = this.mnuAllowPrint.Checked;
            this.axUdPdf.EnablePrint = this.mnuAllowPrint.Checked;
        }

        private void mnuAllowCapture_Click(object sender, EventArgs e)
        {
            this.mnuAllowCapture.Checked = !this.mnuAllowCapture.Checked;
            this.axUdPdf.EnableCapture = this.mnuAllowCapture.Checked;
        }

        //动态水印演示
        int water1 = -1;
        int water2 = -1;
        private void mnuWaterMark_Click(object sender, EventArgs e)
        {
            if (water1 > -1)
            {
                this.axUdPdf.RemoveWaterMark(water1);
                water1 = -1;
            }
            else
            {
                this.axUdPdf.SetWaterFont("宋体", 20, 100, true, false, false, false);
                water1 = this.axUdPdf.AddWaterText("这里是动态添加的水印", 20, 100);
            }

            if (water2 > -1)
            {
                this.axUdPdf.RemoveWaterMark(water2);
                water2 = -1;
            }
            else
            {
                this.axUdPdf.SetWaterFont("宋体", 40, 300, false, false, false, false);
                water2 = this.axUdPdf.AddWaterText("斜体的水印文字", 100, 300, 50, 45, 0, 0);
            }
            this.mnuWaterMark.Checked = !this.mnuWaterMark.Checked;
        }

        #endregion

        private void mnuAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("UUDoc PDF Control Sample for Windows\r\n\r\n(C)2013 珠海市优道信息科技有限公司", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void mnuWebSite_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.uudoc.com");
        }

        

    }
}
