基本信息
源码名称:c#中winform窗体进行打印
源码大小:0.19M
文件格式:.rar
开发语言:C#
更新时间:2018-01-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Print { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.printDocument1.OriginAtMargins = true;//启用页边距 this.pageSetupDialog1.EnableMetric = true;//以毫米为单位 } private void button1_Click(object sender, EventArgs e) { this.pageSetupDialog1.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { this.printPreviewDialog1.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { if (this.printDialog1.ShowDialog() == DialogResult.OK) { this.printDocument1.Print(); } } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { ////打印内容 为 局部的 this.groupBox1 //Bitmap _NewBitmap = new Bitmap(groupBox1.Width, groupBox1.Height); //groupBox1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height)); //e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height); ////打印内容 为 整个Form //Image myFormImage; //myFormImage = new Bitmap(this.Width, this.Height); //Graphics g = Graphics.FromImage(myFormImage); //g.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size); //e.Graphics.DrawImage(myFormImage, 0, 0); //打印内容 为 自定义文本内容 //Font font = new Font("宋体", 12); //Brush bru = Brushes.Blue; //for (int i = 1; i <= 5; i ) //{ // e.Graphics.DrawString("Hello world ", font, bru, i * 20, i * 20); //} Graphics MyGraphics = e.Graphics;//获得绘图对象 SolidBrush drawBrush = new SolidBrush(Color.Black); Font drawFont = new Font("方正魏碑简体", 15, FontStyle.Bold); Font drawFont1 = new Font("华文细黑", 9); Color color = Color.Black; Pen myPen = new Pen(color, 1); MyGraphics.DrawString("会 客 单", drawFont, drawBrush, 100, 0); MyGraphics.DrawString("登记时间:" DateTime.Now.ToString(), drawFont1, drawBrush, 10, 45); MyGraphics.DrawRectangle(myPen, 0, 62, 68, 30); MyGraphics.DrawString("访客姓名", drawFont1, drawBrush, 8, 70); MyGraphics.DrawRectangle(myPen, 68, 62, 110, 30); string name = username.Text; if (name.Length > 7) { MyGraphics.DrawString(name.Substring(0, 7), drawFont1, drawBrush, 68, 64); MyGraphics.DrawString(name.Substring(7, name.Length - 7), drawFont1, drawBrush, 68, 77); } else { MyGraphics.DrawString(name, drawFont1, drawBrush, 68, 70); } MyGraphics.DrawRectangle(myPen, 0, 92, 68, 24); MyGraphics.DrawString("访客性别", drawFont1, drawBrush, 8, 97); MyGraphics.DrawRectangle(myPen, 68, 92, 110, 24); MyGraphics.DrawString(sex.Text, drawFont1, drawBrush, 68, 97); MyGraphics.DrawRectangle(myPen, 0, 116, 68, 24); MyGraphics.DrawString("访客电话", drawFont1, drawBrush, 8, 121); MyGraphics.DrawRectangle(myPen, 68, 116, 110, 24); MyGraphics.DrawString(phone.Text, drawFont1, drawBrush, 68, 121); MyGraphics.DrawRectangle(myPen, 0, 140, 68, 24); MyGraphics.DrawString("车牌号码", drawFont1, drawBrush, 8, 145); MyGraphics.DrawRectangle(myPen, 68, 140, 110, 24); MyGraphics.DrawString(carnum.Text, drawFont1, drawBrush, 68, 145); MyGraphics.DrawRectangle(myPen, 0, 164, 68, 24); MyGraphics.DrawString("来访人数", drawFont1, drawBrush, 8, 169); MyGraphics.DrawRectangle(myPen, 68, 164, 110, 24); MyGraphics.DrawString(renshu.Text, drawFont1, drawBrush, 68, 169); MyGraphics.DrawRectangle(myPen, 178, 62, 105, 126); if (pictureBox1.Image != null) { MyGraphics.DrawImage(pictureBox1.Image, 178, 62, 103, 124); } MyGraphics.DrawRectangle(myPen, 0, 188, 68, 24); MyGraphics.DrawString("来访事由", drawFont1, drawBrush, 8, 193); MyGraphics.DrawRectangle(myPen, 68, 188, 215, 24); MyGraphics.DrawString(matter.Text, drawFont1, drawBrush, 68, 193); MyGraphics.DrawRectangle(myPen, 0, 212, 68, 24); MyGraphics.DrawString("证件号码", drawFont1, drawBrush, 8, 217); MyGraphics.DrawRectangle(myPen, 68, 212, 215, 24); MyGraphics.DrawString(card.Text, drawFont1, drawBrush, 68, 217); MyGraphics.DrawRectangle(myPen, 0, 236, 68, 30); MyGraphics.DrawString("证件地址", drawFont1, drawBrush, 8, 244); MyGraphics.DrawRectangle(myPen, 68, 236, 215, 30); string addressstr = address.Text; if (addressstr.Length > 16) { MyGraphics.DrawString(addressstr.Substring(0, 16), drawFont1, drawBrush, 68, 238); MyGraphics.DrawString(addressstr.Substring(16, addressstr.Length - 16), drawFont1, drawBrush, 68, 251); } else { MyGraphics.DrawString(addressstr, drawFont1, drawBrush, 68, 238); } MyGraphics.DrawRectangle(myPen, 0, 266, 68, 24); MyGraphics.DrawString("携带物品", drawFont1, drawBrush, 8, 271); MyGraphics.DrawRectangle(myPen, 68, 266, 215, 24); MyGraphics.DrawString(wupin.Text, drawFont1, drawBrush, 68, 271); MyGraphics.DrawRectangle(myPen, 0, 290, 68, 24); MyGraphics.DrawString("被访人部门", drawFont1, drawBrush, 2, 295); MyGraphics.DrawRectangle(myPen, 68, 290, 215, 24); MyGraphics.DrawString(bfbm.Text, drawFont1, drawBrush, 68, 295); MyGraphics.DrawRectangle(myPen, 0, 314, 68, 24); MyGraphics.DrawString("被访人姓名", drawFont1, drawBrush, 2, 319); MyGraphics.DrawRectangle(myPen, 68, 314, 215, 24); MyGraphics.DrawString(bfxm.Text, drawFont1, drawBrush, 68, 319); MyGraphics.DrawRectangle(myPen, 0, 338, 68, 24); MyGraphics.DrawString("被访人签名", drawFont1, drawBrush, 2, 343); MyGraphics.DrawRectangle(myPen, 68, 338, 143, 24); MyGraphics.DrawRectangle(myPen, 0, 362, 68, 24); MyGraphics.DrawString("登记单号", drawFont1, drawBrush, 8, 367); MyGraphics.DrawRectangle(myPen, 68, 362, 143, 24); MyGraphics.DrawString(djnum.Text, drawFont1, drawBrush, 68, 367); MyGraphics.DrawRectangle(myPen, 0, 386, 211, 24); MyGraphics.DrawString("请妥善保留,离开时交换门卫", drawFont1, drawBrush, 25, 391); MyGraphics.DrawRectangle(myPen, 211, 338, 72, 72); if (pictureBox2.Image != null) { MyGraphics.DrawImage(pictureBox2.Image, 211, 338, 72, 72); } } } }