namespace Drive_PrintFrom { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region 定义全局变量及对象 Brush myBrush = new SolidBrush(Color.Black); Pen mypen = new Pen(Color.Black); Font myFont = new Font("宋体", 13); #endregion private void button1_Click(object sender, EventArgs e) { /* //实例化打印对象 PrintDocument printDocument1 = new PrintDocument(); //设置打印用的纸张,当设置为Custom的时候,可以自定义纸张的大小 printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", 500, 500); //注册PrintPage事件,打印每一页时会触发该事件 printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); //初始化打印对话框对象 PrintDialog printDialog1 = new PrintDialog(); //将PrintDialog.UseEXDialog属性设置为True,才可显示出打印对话框 printDialog1.UseEXDialog = true; //将printDocument1对象赋值给打印对话框的Document属性 printDialog1.Document = printDocument1; //打开打印对话框 DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) printDocument1.Print();//开始打印*/ //设置printDialog控件的Document属性,设置操作文档 printDialog1.Document = printDocument1; //启用"打印到文件"复选框 printDialog1.AllowPrintToFile = true; //显示“当前项”按钮 printDialog1.AllowCurrentPage = true; //启用"选择按钮" printDialog1.AllowSelection = true; //启用"页"按钮 printDialog1.AllowSomePages = true; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) printDocument1.Print();//开始打印 } private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { int printWidth = e.PageBounds.Width; int printHeight = e.PageBounds.Height; //左侧 e.Graphics.DrawString("附件", new Font("宋体", 17, FontStyle.Bold), myBrush, 50, 50); e.Graphics.DrawString("道路货运运单", new Font("宋体", 16, FontStyle.Bold), myBrush, 200, 100); e.Graphics.DrawString("(存根联)", new Font("宋体", 14), myBrush, 265, 135); e.Graphics.DrawString("运单编号:", new Font("宋体", 12, FontStyle.Bold), myBrush, 162, 160); e.Graphics.DrawString("货物装载源头单位:(盖章)", new Font("宋体", 13), myBrush, 120, 220); e.Graphics.DrawString("货物装载源头单位联系电话:", new Font("宋体", 13), myBrush, 120, 250); e.Graphics.DrawString("车辆号牌:__________(黄)", new Font("宋体", 13), myBrush, 120, 280); e.Graphics.DrawString("车辆道路运输证号:", new Font("宋体", 13), myBrush, 120, 310); e.Graphics.DrawString("挂车号牌:__________(黄)", new Font("宋体", 13), myBrush, 120, 340); e.Graphics.DrawString("挂车道路运输证号:", new Font("宋体", 13), myBrush, 120, 370); e.Graphics.DrawString("轴型:_____轴;车货总质量限值:______吨", new Font("宋体", 12), myBrush, 120, 400); e.Graphics.DrawString("驾驶员姓名:", new Font("宋体", 13), myBrush, 120, 430); e.Graphics.DrawString("驾驶员从业资格证:", new Font("宋体", 13), myBrush, 120, 460); e.Graphics.DrawString("货物品种:", new Font("宋体", 13), myBrush, 120, 490); e.Graphics.DrawString("车货总重:___________吨", new Font("宋体", 13), myBrush, 120, 520); e.Graphics.DrawString("起运地:", new Font("宋体", 13), myBrush, 120, 550); e.Graphics.DrawString("托运单位:", new Font("宋体", 13), myBrush, 120, 580); e.Graphics.DrawString("送达地:", new Font("宋体", 13), myBrush, 120, 610); e.Graphics.DrawString("收货单位:", new Font("宋体", 13), myBrush, 120, 640); //填充右侧内容 e.Graphics.DrawString("道路货运运单", new Font("宋体", 16, FontStyle.Bold), myBrush, 750, 100); e.Graphics.DrawString("(随车备查联)", new Font("宋体", 14), myBrush, 800, 135); e.Graphics.DrawString("运单编号:", new Font("宋体", 12, FontStyle.Bold), myBrush, 680, 160); e.Graphics.DrawString("货物装载源头单位:(盖章)", myFont, myBrush, 620, 220); e.Graphics.DrawString("货物装载源头单位联系电话:", myFont, myBrush, 620, 250); e.Graphics.DrawString("车辆号牌:__________(黄)", myFont, myBrush, 620, 280); e.Graphics.DrawString("车辆道路运输证号:", myFont, myBrush, 620, 310); e.Graphics.DrawString("挂车号牌:__________(黄)", myFont, myBrush, 620, 340); e.Graphics.DrawString("挂车道路运输证号:", myFont, myBrush, 620, 370); e.Graphics.DrawString("轴型:_____轴;车货总质量限值:______吨", myFont, myBrush, 620, 400); e.Graphics.DrawString("驾驶员姓名:", myFont, myBrush, 620, 430); e.Graphics.DrawString("驾驶员从业资格证:", myFont, myBrush, 620, 460); e.Graphics.DrawString("货物品种:", myFont, myBrush, 620, 490); e.Graphics.DrawString("车货总重:___________吨", myFont, myBrush, 620, 520); e.Graphics.DrawString("起运地:", myFont, myBrush, 620, 550); e.Graphics.DrawString("托运单位:", myFont, myBrush, 620, 580); e.Graphics.DrawString("送达地:", myFont, myBrush, 620, 610); e.Graphics.DrawString("收货单位:", myFont, myBrush, 620, 640); } } }
标签:宋体,打印机,myBrush,打印,选择,DrawString,Graphics,new,Font From: https://www.cnblogs.com/Guyunanqi/p/16828188.html