資源簡(jiǎn)介
套打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(); //打印文檔對(duì)象 Font printFont; //打印使用的字體 public Form1() { InitializeComponent(); } void printDt_PrintPage(object sender, PrintPageEventArgs e) { float pointX = 10; float pointY = 10; e.Graphics.DrawString("打印內(nèi)容", 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("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 35); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 56, pointX 300, pointY 56); e.Graphics.DrawString("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 65); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 86, pointX 300, pointY 86); e.Graphics.DrawString("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 95); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 116, pointX 300, pointY 116); e.Graphics.DrawString("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 125); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 146, pointX 300, pointY 146); e.Graphics.DrawString("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 155); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 176, pointX 300, pointY 176); e.Graphics.DrawString("打印內(nèi)容", printFont, Brushes.Black, pointX, pointY 185); e.Graphics.DrawLine(new Pen(Color.Black), pointX, pointY 206, pointX 300, pointY 206); e.Graphics.DrawString("檢測(cè)結(jié)果", printFont, Brushes.Black, pointX, pointY 233); e.Graphics.DrawString("通過(guò)", 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();???//打印文檔對(duì)象
????????Font?printFont;????//打印使用的字體
????????public?Form1()
????????{
????????????InitializeComponent();
????????????
????????}
????????void?printDt_PrintPage(object?sender?PrintPageEventArgs?e)
????????{
????????????float?pointX?=?10;
????????????float?pointY?=?10;
????????????e.Graphics.DrawString(“打印內(nèi)容“?new?Font(“宋體“?16F)?Brushes.Black?pointX+60?pointY);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?26pointX?+?300pointY?+?26);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY+35);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?56?pointX?+?300?pointY?+?56);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY?+?65);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?86?pointX?+?300?pointY?+?86);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY?+?95);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?116?pointX?+?300?pointY?+?116);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY?+?125);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?146?pointX?+?300?pointY?+?146);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY?+?155);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?176?pointX?+?300?pointY?+?176);
????????????e.Graphics.DrawString(“打印內(nèi)容“?printFont?Brushes.Black?pointX?pointY?+?185);
????????????e.Graphics.DrawLine(new?Pen(Color.Black)?pointX?pointY?+?206?pointX?+?300?pointY?+?206);
????????????e.Graphics.DrawString(“檢測(cè)結(jié)果“?printFont?Brushes.Black?pointX?pointY?+?233);
????????????e.Graphics.DrawString(“通過(guò)“?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;
??????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????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個(gè)文件信息
評(píng)論
共有 條評(píng)論