⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 explorerpanel.cs

📁 用C#實現能產生PDF格式文件的源碼
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using PdfSharp.Explorer.Pages;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.Advanced;

namespace PdfSharp.Explorer
{
  /// <summary>
  /// 
  /// </summary>
  public class ExplorerPanel : System.Windows.Forms.UserControl
  {
    private System.Windows.Forms.ColumnHeader id;
    private System.Windows.Forms.ColumnHeader type;
    internal System.Windows.Forms.ListView lvObjects;
    private System.Windows.Forms.TabPage tpObjects;
    private System.Windows.Forms.TabPage tpInfo;
    internal System.Windows.Forms.ListBox lbxInfo;
    private System.Windows.Forms.TabControl tbcNavigation;
    private System.Windows.Forms.TabPage tpPages;
    internal System.Windows.Forms.ListView lvPages;
    private System.Windows.Forms.ColumnHeader clmPage;
    private System.Windows.Forms.Panel pnlNavigation;
    private System.Windows.Forms.Splitter splitter;
    private System.Windows.Forms.Panel pnlWorkArea;
    private System.Windows.Forms.TabPage tpPdf;
    private System.Windows.Forms.TabPage tpData;
    private System.Windows.Forms.ColumnHeader clmSize;
    private System.Windows.Forms.TabControl tbcMain;
    private System.ComponentModel.Container components = null;

    public ExplorerPanel(MainForm mainForm)
    {
      this.mainForm = mainForm;
      this.process = mainForm.Process;
      InitializeComponent();

      PageBase page = new PdfTextPage(this);
      this.tbcMain.TabPages[1].Controls.Add(page);
      page.Dock = DockStyle.Fill;
    }

    public MainForm MainForm
    {
      get {return this.mainForm;}
    }
    MainForm mainForm;

    public void OnNewDocument()
    {
      this.process = this.mainForm.Process;
      
      PdfObject[] objects = this.process.Document.Internals.AllObjects;
      this.lvObjects.Items.Clear();
      for (int idx = 0; idx < objects.Length; idx++)
      {
        PdfObject obj = objects[idx];
        ListViewItem item = new ListViewItem(new string[2]{PdfInternals.GetObjectID(obj).ToString(), ExplorerProcess.GetTypeName(obj)});
        item.Tag = obj;
        this.lvObjects.Items.Add(item);
      }

      PdfPages pages = this.process.Document.Pages;
      this.lvPages.Items.Clear();
      for (int idx = 0; idx < pages.Count; idx++)
      {
        PdfPage page = pages[idx];
        ListViewItem item = new ListViewItem(new string[2]{(idx + 1).ToString(), 
          ExplorerHelper.PageSize(page, this.mainForm.Process.IsMetric)});
          //String.Format("{0:0} x {1:0} mm", XUnit.FromPoint(page.Width).Millimeter,XUnit.FromPoint(page.Height).Millimeter)});
        item.Tag = page;
        this.lvPages.Items.Add(item);
      }

      this.process.Navigator.SetNext(this.process.Document.Info);
      ActivatePage("Info");
    }

    public ExplorerProcess Process
    {
      get { return this.process; }
    }
    ExplorerProcess process;

    public void NavigateTo(PdfItem item)
    {
    }

    void ActivatePage(string name)
    {
      if (this.currentPage != null)
      {
        if (this.currentPage.Tag.Equals(name))
        {
          this.currentPage.UpdateDocument();
          return;
        }
        this.tpData.Controls.Remove(this.currentPage);
        this.currentPage = null;
      }

      switch (name)
      {
        case "Info":
          if (this.infoPage == null)
            this.infoPage = new MainInformationPage(this);
          this.currentPage = this.infoPage;
          break;

        case "Pages":
          if (this.pagesPage == null)
            this.pagesPage = new MainPagesPage(this);
          this.currentPage = this.pagesPage;
          this.currentPage.Dock = DockStyle.Fill;
          break;

        case "Objects":
          if (this.objectsPage == null)
            this.objectsPage = new MainObjectsPage(this);
          this.currentPage = this.objectsPage;
          this.currentPage.Dock = DockStyle.Fill;
          break;

        //case "Tree":
        //  if (this.treePage == null)
        //    this.treePage = new MainTreePage(this);
        //  this.currentPage = this.treePage;
        //  this.currentPage.Dock = DockStyle.Fill;
        //  break;

        default:
          throw new NotImplementedException("tag: " + name);
      }
      this.tpData.Controls.Add(this.currentPage);
    }
    PageBase currentPage;
    PageBase infoPage;
    PageBase pagesPage;
    PageBase objectsPage;
    //PageBase treePage;

    /// <summary> 
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        if (components != null)
          components.Dispose();
      }
      base.Dispose(disposing);
    }

    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad (e);
      ActivatePage("Info");
    }

    void ActivateTab(PdfObject value)
    {
      switch (this.tbcMain.SelectedIndex)
      {
          // Data
        case 0:
          if (this.tbcMain.TabPages[0].Controls[0] is MainObjectsPageBase)
            ((MainObjectsPageBase)this.tbcMain.TabPages[0].Controls[0]).ActivatePage(value);
          break;

          // PDF
        case 1:
          ((PdfTextPage)this.tbcMain.TabPages[1].Controls[0]).SetObject(value);
          break;
      }
    }



    #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()
    {
      this.tbcNavigation = new System.Windows.Forms.TabControl();
      this.tpInfo = new System.Windows.Forms.TabPage();
      this.lbxInfo = new System.Windows.Forms.ListBox();
      this.tpObjects = new System.Windows.Forms.TabPage();
      this.lvObjects = new System.Windows.Forms.ListView();
      this.id = new System.Windows.Forms.ColumnHeader();
      this.type = new System.Windows.Forms.ColumnHeader();
      this.tpPages = new System.Windows.Forms.TabPage();
      this.lvPages = new System.Windows.Forms.ListView();
      this.clmPage = new System.Windows.Forms.ColumnHeader();
      this.clmSize = new System.Windows.Forms.ColumnHeader();
      this.pnlNavigation = new System.Windows.Forms.Panel();
      this.splitter = new System.Windows.Forms.Splitter();
      this.pnlWorkArea = new System.Windows.Forms.Panel();
      this.tbcMain = new System.Windows.Forms.TabControl();
      this.tpData = new System.Windows.Forms.TabPage();
      this.tpPdf = new System.Windows.Forms.TabPage();
      this.tbcNavigation.SuspendLayout();
      this.tpInfo.SuspendLayout();
      this.tpObjects.SuspendLayout();
      this.tpPages.SuspendLayout();
      this.pnlNavigation.SuspendLayout();
      this.pnlWorkArea.SuspendLayout();
      this.tbcMain.SuspendLayout();
      this.SuspendLayout();
      // 
      // tbcNavigation
      // 
      this.tbcNavigation.Alignment = System.Windows.Forms.TabAlignment.Left;
      this.tbcNavigation.Controls.Add(this.tpInfo);
      this.tbcNavigation.Controls.Add(this.tpObjects);
      this.tbcNavigation.Controls.Add(this.tpPages);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -