• 大小: 21KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-04-01
  • 语言: C#
  • 标签: c#  格式化  打印  套打  

资源简介

开发环境: VS2005 包含: 1、格式化打印控件PrintControl.dll 及源码 2、打印模板示例PrtTemplate.xml 3、调用PrintControl.dll 使用打印模板进行打印的例子 特点: 1、XML模板可设置打印条目的位置,字体,大小 2、支持预览打印,直接打印等 3、具体使用方法参见调用例“PrintControlTest” 代码简单明了,可作为格式化打印,套打程序参考,希望对您有所启发和帮助,谢谢:)

资源截图

代码片段和文件信息

using System;
using System.xml;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;


namespace UDF.GUI.PrintControl
{
    public class FormatPrint
    {

        private SortedList m_PrintPoint_List = new SortedList();
        /// 
        /// 从打印模版文件中读取点阵数据,并保存到Hash表中
        /// 

        /// 
        public  void loadPrintTemplate(string p_tempateFile)
        {
            xmlDocument xmlDoc = new xmlDocument();
            xmlDoc.Load(p_tempateFile);
            xmlElement xmlNodePoints = xmlDoc[“Points“];
            xmlNodeList nodelist = xmlNodePoints.ChildNodes;
            m_PrintPoint_List.Clear();
            foreach (xmlElement el in nodelist)//读元素值 
            {

                OnePrintPoint op = new OnePrintPoint();
                op.Key = el.Attributes[“Key“].InnerText;
                op.FontName = el.Attributes[“FontName“].InnerText;
                op.FontSize = float.Parse(el.Attributes[“FontSize“].InnerText);
                op.X = float.Parse(el.Attributes[“X“].InnerText);
                op.Y = float.Parse(el.Attributes[“Y“].InnerText);
                m_PrintPoint_List.Add(op.Key.ToUpper() op);
            }
        }
        //private FormatPrint()
        //{
        //}
        //public FormatPrint(string p_tempateFile)
        //{
        //    loadPrintTemplate(p_tempateFile);
        //}
        /// 
        /// 设置打印点的值
        /// 

        /// 
        /// 
        public void SetValue(string p_Key string p_Value)
        {
            p_Key = p_Key.ToUpper();
            if (m_PrintPoint_List.Contains(p_Key))
            {
                OnePrintPoint tmpOnePrintPoint = (OnePrintPoint)m_PrintPoint_List[p_Key];
                tmpOnePrintPoint.Value = p_Value;
            }
            else
            {
               throw new Exception (“打印模版中不存在Key为“ + p_Key+“的节点“);
            }
        }
        /// 
        /// 直接打印
        /// 

 
        public void Print( )
        {
            Print(false);
        }
        /// 
        /// 直接打印
        /// 

        /// 
        public void Print(bool p_ShowPrintDialog)
        {
            try
            {
                PrintDocument pd = new PrintDocument();

                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                if (p_ShowPrintDialog)
                {
                    PrintDialog pdlg = new PrintDialog();
                    pdlg.Document = pd;
                    DialogResult res = pdlg.ShowDialog();
                    if (res == DialogResult.OK)
                        pd.Print();
                }
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-03-09 15:47  PrintControl\
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\
     文件        1429  2009-03-09 15:38  PrintControl\PrintControl.sln
     文件       18944  2009-03-09 15:47  PrintControl\PrintControl.suo
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\bin\
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\bin\Debug\
     文件        5632  2005-11-11 22:25  PrintControl\PrintControlTest\bin\Debug\PrintControlTest.vshost.exe
     文件        1614  2009-03-09 15:43  PrintControl\PrintControlTest\Form1.cs
     文件        3504  2009-01-07 17:54  PrintControl\PrintControlTest\Form1.Designer.cs
     文件        5814  2009-01-07 17:54  PrintControl\PrintControlTest\Form1.resx
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\obj\
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\obj\Debug\
     目录           0  2009-03-09 15:47  PrintControl\PrintControlTest\obj\Debug\TempPE\
     文件        3649  2009-03-09 15:42  PrintControl\PrintControlTest\PrintControlTest.csproj
     文件         475  2009-01-07 16:39  PrintControl\PrintControlTest\Program.cs
     目录           0  2009-03-09 15:28  PrintControl\PrintControlTest\Properties\
     文件        1180  2009-01-07 16:39  PrintControl\PrintControlTest\Properties\AssemblyInfo.cs
     文件        2854  2009-03-09 15:42  PrintControl\PrintControlTest\Properties\Resources.Designer.cs
     文件        5612  2009-01-07 16:39  PrintControl\PrintControlTest\Properties\Resources.resx
     文件        1112  2009-03-09 15:42  PrintControl\PrintControlTest\Properties\Settings.Designer.cs
     文件         249  2009-01-07 16:39  PrintControl\PrintControlTest\Properties\Settings.settings
     文件         838  2009-03-09 15:42  PrintControl\PrintControlTest\PrtTemplate.xml
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\bin\
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\bin\Debug\
     文件        6572  2009-03-09 15:39  PrintControl\PrintControl\FormatPrint.cs
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\obj\
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\obj\Debug\
     目录           0  2009-03-09 15:47  PrintControl\PrintControl\obj\Debug\TempPE\
     文件        2076  2009-03-09 15:42  PrintControl\PrintControl\PrintControl.csproj
     目录           0  2009-03-09 15:29  PrintControl\PrintControl\Properties\
............此处省略2个文件信息

评论

共有 条评论