• 大小: 0.03M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-26
  • 语言: C#
  • 标签: demo  套打  打印  

资源简介

套打Demo


【核心代码】

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

namespace Print_Demo
{
    public partial class Form1 : Form
    {
        public PrintDocument printDt = new PrintDocument();   //打印文档对象
        Font printFont;    //打印使用的字体
        public Form1()
        {
            InitializeComponent();
            
        }

        void printDt_PrintPage(object sender, PrintPageEventArgs e)
        {

            float pointX = 10;
            float pointY = 10;
            e.Graphics.DrawString("打印内容", new Font("宋体", 16F), Brushes.Black, pointX 60, pointY);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   26,pointX   300,pointY   26);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY 35);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   56, pointX   300, pointY   56);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY   65);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   86, pointX   300, pointY   86);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY   95);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   116, pointX   300, pointY   116);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY   125);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   146, pointX   300, pointY   146);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY   155);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   176, pointX   300, pointY   176);

            e.Graphics.DrawString("打印内容", printFont, Brushes.Black, pointX, pointY   185);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   206, pointX   300, pointY   206);

            e.Graphics.DrawString("检测结果", printFont, Brushes.Black, pointX, pointY   233);
            e.Graphics.DrawString("通过", new Font("宋体",22F,FontStyle.Bold), Brushes.Black, pointX 90, pointY   225);
            e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY   265, pointX   300, pointY   265);

            e.Graphics.DrawString("单位名称", printFont, Brushes.Black, pointX, pointY   275);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            printDt.PrintPage  = new PrintPageEventHandler(printDt_PrintPage);
            printFont = new Font("宋体", 12F);
            
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            //PrintDialog printDlg = new PrintDialog();
            //printDlg.Document = printDt;
            //printDlg.AllowPrintToFile = true;
            //printDlg.AllowCurrentPage = true;
            //printDlg.AllowSelection = true;
            //printDlg.ShowDialog();
           
            //printDlg.ShowDialog();
            printDt.Print();
        }

        private void btnLook_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog printPreview = new PrintPreviewDialog();

            printPreview.PrintPreviewControl.Document = printDt;
            printPreview.ShowDialog(this);
        }
    }
}

资源截图

代码片段和文件信息

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

namespace Print_Demo
{
    public partial class Form1 : Form
    {
        public PrintDocument printDt = new PrintDocument();   //打印文档对象
        Font printFont;    //打印使用的字体
        public Form1()
        {
            InitializeComponent();
            
        }

        void printDt_PrintPage(object sender PrintPageEventArgs e)
        {

            float pointX = 10;
            float pointY = 10;
            e.Graphics.DrawString(“打印内容“ new Font(“宋体“ 16F) Brushes.Black pointX+60 pointY);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 26pointX + 300pointY + 26);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY+35);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 56 pointX + 300 pointY + 56);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY + 65);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 86 pointX + 300 pointY + 86);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY + 95);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 116 pointX + 300 pointY + 116);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY + 125);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 146 pointX + 300 pointY + 146);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY + 155);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 176 pointX + 300 pointY + 176);

            e.Graphics.DrawString(“打印内容“ printFont Brushes.Black pointX pointY + 185);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 206 pointX + 300 pointY + 206);

            e.Graphics.DrawString(“检测结果“ printFont Brushes.Black pointX pointY + 233);
            e.Graphics.DrawString(“通过“ new Font(“宋体“22FFontstyle.Bold) Brushes.Black pointX+90 pointY + 225);
            e.Graphics.DrawLine(new Pen(Color.Black) pointX pointY + 265 pointX + 300 pointY + 265);

            e.Graphics.DrawString(“单位名称“ printFont Brushes.Black pointX pointY + 275);
        }

        private void Form1_Load(object sender EventArgs e)
        {
            printDt.PrintPage += new PrintPageEventHandler(printDt_PrintPage);
            printFont = new Font(“宋体“ 12F);
            
        }

        private void btnPrint_Click(object sender EventArgs e)
        {
            //PrintDialog printDlg = new PrintDialog();
            //printDlg.Document = printDt;
            //printDlg.AllowPrintToFile = true;
            //printDlg.AllowCurrentPage = true;
            //printDlg.AllowSelection = true;
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        391  2009-03-17 12:04  套打Demo\Print_Demo\Print_Demo\bin\Debug\ddd

     文件      20480  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\bin\Debug\Print_Demo.exe

     文件      24064  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\bin\Debug\Print_Demo.pdb

     文件       5632  2005-11-11 22:25  套打Demo\Print_Demo\Print_Demo\bin\Debug\Print_Demo.vshost.exe

     目录          0  2009-03-17 12:04  套打Demo\Print_Demo\Print_Demo\bin\Debug

     目录          0  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\bin

     文件       3522  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\Form1.cs

     文件       2727  2009-03-17 12:09  套打Demo\Print_Demo\Print_Demo\Form1.Designer.cs

     文件       5814  2009-03-17 12:09  套打Demo\Print_Demo\Print_Demo\Form1.resx

     文件        842  2009-03-17 12:09  套打Demo\Print_Demo\Print_Demo\obj\Debug\Print_Demo.csproj.GenerateResource.Cache

     文件      20480  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\obj\Debug\Print_Demo.exe

     文件        180  2009-03-17 12:09  套打Demo\Print_Demo\Print_Demo\obj\Debug\Print_Demo.Form1.resources

     文件      24064  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\obj\Debug\Print_Demo.pdb

     文件        180  2009-03-17 11:55  套打Demo\Print_Demo\Print_Demo\obj\Debug\Print_Demo.Properties.Resources.resources

     目录          0  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\obj\Debug\TempPE

     目录          0  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\obj\Debug

     文件        753  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo\obj\Print_Demo.csproj.FileListAbsolute.txt

     目录          0  2009-03-17 11:55  套打Demo\Print_Demo\Print_Demo\obj

     文件       3227  2009-03-17 11:55  套打Demo\Print_Demo\Print_Demo\Print_Demo.csproj

     文件        469  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Program.cs

     文件       1174  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties\AssemblyInfo.cs

     文件       2876  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties\Resources.Designer.cs

     文件       5612  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties\Resources.resx

     文件       1095  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties\Settings.Designer.cs

     文件        249  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties\Settings.settings

     目录          0  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo\Properties

     目录          0  2010-09-30 13:25  套打Demo\Print_Demo\Print_Demo

     文件        919  2009-03-17 11:25  套打Demo\Print_Demo\Print_Demo.sln

    ..A..H.     12800  2010-09-30 14:07  套打Demo\Print_Demo\Print_Demo.suo

     目录          0  2009-03-17 11:25  套打Demo\Print_Demo

............此处省略4个文件信息

评论

共有 条评论