csharp customer style print
/// <summary> /// 自定格式設置打印 /// 塗聚文 /// 締友計算機信息技術有限公司 /// Geovin Du /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { try { // printDocument1.DefaultPageSettings.Landscape = true; //橫向打印 //if (File.Exists(path + "\\2.png")) //{ // File.Delete(path + "\\2.png"); // GC.Collect(); //} //1 Pdf417lib pft417 = new Pdf417lib(); Bitmap bit; bit = Pdf417lib.GenerateBitmap("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 90, 30); pft417.Options = Pdf417lib.PDF417_INVERT_BITMAP; pft417.paintCode(); //bit.Save(path + "\\2.png"); //im = Image.FromFile(path + "\\2.png"); im = Image.FromHbitmap(bit.GetHbitmap()); //2 //Image qrbit; //Bitmap qrb; //QRCode barcode = new QRCode(); //barcode.Code = "362425"; //barcode.BarcodeWidth = 50; //barcode.BarcodeHeight = 50; //barcode.drawBarcode2ImageFile(path + "\\3.png"); //qrb=barcode.drawBarcodeOnBitmap(); //qrbit = Image.FromFile(path + "\\3.png"); //3 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); String encoding = "362425L00093"; qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC; int scale = 4; qrCodeEncoder.QRCodeScale = scale; int version = 4; qrCodeEncoder.QRCodeVersion = version; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; System.Drawing.Image image; String data = encoding; image = qrCodeEncoder.Encode(data); //image.Save(path+"\\geovindu.png",System.Drawing.Imaging.ImageFormat.Png); string imagePath = path + "\\1.png"; Image temp = Image.FromFile(imagePath); int printWidth = e.PageBounds.Width;//页面宽度 827* 1169 英寸 int printHeight = e.PageBounds.Height;//页面高度1169 int left = 15;//printWidth / 2 - int right = printWidth / 2 + 15;// int top = 10;//printHeight / 2 - Brush myBrush = new SolidBrush(System.Drawing.Color.Black);//创建Brush对象 Pen mypen = new Pen(System.Drawing.Color.Black);//创建Pen对象 Font myFont = new Font("宋体", 10);//创建Font对象 Font headFont = new Font("宋体", 8); Font conFont = new Font("宋体", 7); //Rectangle destRect = new Rectangle(right + 280, top - 5, 50, 50); //80, 20 Rectangle destRect = new Rectangle(right + 280, top - 5, 90, 30); e.Graphics.DrawImage(im, destRect, 0, 0, im.Width, im.Height, System.Drawing.GraphicsUnit.Pixel);//圖片image e.Graphics.DrawString("締友計算機信息技術(深圳)有限公司" + DateTime.Now.Year.ToString() + "年" + (DateTime.Now.Month - 1).ToString() + "月份工資单", new Font("宋体", 10, FontStyle.Bold), myBrush, new Point(32, top));//绘制标题 e.Graphics.DrawLine(new Pen(System.Drawing.Color.Black, 2), 32, top + 20, 680, top + 20);//绘制线条 #region //e.Graphics.DrawRectangle(mypen, left, top + 62, 810, 230);//绘制矩形框 //e.Graphics.DrawLine(mypen, left + 50, top + 62, left + 50, top + 293);//绘制第一列网格线 //e.Graphics.DrawLine(mypen, left + 80, top + 62, left + 80, top + 293);//绘制第二列网格线 //e.Graphics.DrawLine(mypen, left + 180, top + 62, left + 180, top + 293);//绘制第四列网格线 //e.Graphics.DrawLine(mypen, left + 80, top + 122, left + 180, top + 122);//绘制第二行网格线 //e.Graphics.DrawLine(mypen, left + 130, top + 122, left + 130, top + 293);//绘制第三列网格线 //e.Graphics.DrawLine(mypen, left + 240, top + 62, left + 240, top + 293);//绘制第五列网格线 //e.Graphics.DrawLine(mypen, left + 290, top + 62, left + 290, top + 293);//绘制第六列网格线 //e.Graphics.DrawLine(mypen, left + 290, top + 122, left + 440, top + 122);//绘制第二行网格线 //e.Graphics.DrawLine(mypen, left + 340, top + 122, left + 340, top + 293);//绘制第七列网格线 //e.Graphics.DrawLine(mypen, left + 390, top + 122, left + 390, top + 293);//绘制第八列网格线 //e.Graphics.DrawLine(mypen, left + 440, top + 62, left + 440, top + 293);//绘制第九列网格线 //e.Graphics.DrawLine(mypen, left + 490, top + 62, left + 490, top + 293);//绘制第10列网格线 //e.Graphics.DrawLine(mypen, left + 540, top + 62, left + 540, top + 293);//绘制第11列网格线 //e.Graphics.DrawLine(mypen, left + 590, top + 62, left + 590, top + 293);//绘制第12列网格线 //e.Graphics.DrawLine(mypen, left + 640, top + 62, left + 640, top + 293);//绘制第13列网格线 //e.Graphics.DrawLine(mypen, left + 640, top + 122, left + 740, top + 122);//绘制第二行网格线 //e.Graphics.DrawLine(mypen, left + 690, top + 122, left + 690, top + 293);//绘制第14列网格线 //e.Graphics.DrawLine(mypen, left + 740, top + 62, left + 740, top + 293);//绘制第15列网格线 //e.Graphics.DrawLine(mypen, left, top + 182, 825, top + 182);//绘制第三行网格线 ////绘制第1行数据 //e.Graphics.DrawString("姓名", headFont, myBrush, new Point(left, top + 65)); //e.Graphics.DrawString(strName, conFont, myBrush, new Point(left, top + 185)); #endregion //繪制第一個表格(10列3行) e.Graphics.DrawRectangle(mypen, left, top + 50, 780, 125);//绘制矩形框 int k1 = (int)((19 * 100) / 25.4 + 1); int k2 = (int)((14.8 * 100) / 25.4 + 1); int t1 = (int)((10 * 100) / 25.4 + 1); int t2 = (int)((11 * 100) / 25.4 + 1); e.Graphics.DrawLine(mypen, left + k1, top + 50, left + k1, top + 175);//绘制第1列网格线 e.Graphics.DrawLine(mypen, left + k1 * 2, top + 50, left + k1 * 2, top + 175);//绘制第2列网格线 e.Graphics.DrawLine(mypen, left + k1 * 3, top + 50, left + k1 * 3, top + 175);//绘制第3列网格线 e.Graphics.DrawLine(mypen, left + k1 * 4, top + 50 + t1, left + k1 * 4, top + 175);//绘制第4列网格线 e.Graphics.DrawLine(mypen, left + k1 * 5, top + 50, left + k1 * 5, top + 175);//绘制第5列网格线 e.Graphics.DrawLine(mypen, left + k1 * 3, top + 50 + t1, left + k1 * 5, top + 50 + t1);//绘制第1行网格线 e.Graphics.DrawLine(mypen, left + k1 * 6, top + 50, left + k1 * 6, top + 175);//绘制第6列网格线 e.Graphics.DrawLine(mypen, left, top + 50 + t1 + t2, 795, top + 50 + t1 + t2);//绘制第2行网格线 e.Graphics.DrawLine(mypen, left + k1 * 7, top + 50, left + k1 * 7, top + 175);//绘制第7列网格线 e.Graphics.DrawLine(mypen, left + k1 * 8, top + 50 + t1, left + k1 * 8, top + 175);//绘制第8列网格线 e.Graphics.DrawLine(mypen, left + k1 * 9, top + 50 + t1, left + k1 * 9, top + 175);//绘制第9列网格线 e.Graphics.DrawLine(mypen, left + k1 * 7, top + 50 + t1, 795, top + 50 + t1);//绘制第2行网格线 //第一個標題列 e.Graphics.DrawString("工號", headFont, myBrush, new Point(left + 15, top + 85)); e.Graphics.DrawString(strNo, conFont, myBrush, new Point(left + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("姓名", headFont, myBrush, new Point(left + k1 + 15, top + 85)); e.Graphics.DrawString(strName, conFont, myBrush, new Point(left + k1 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("戶藉", headFont, myBrush, new Point(left + k1 * 2 + 15, top + 85)); e.Graphics.DrawString(strNation, conFont, myBrush, new Point(left + k1 * 2 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("正常工作時間工資", headFont, myBrush, new Point(left + k1 * 3 + 15, top + 65)); e.Graphics.DrawString("基本薪金", headFont, myBrush, new Point(left + k1 * 3 + 15, top + t1 + 65)); e.Graphics.DrawString(strBasicSalary, conFont, myBrush, new Point(left + k1 * 3 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("崗位工資", headFont, myBrush, new Point(left + k1 * 4 + 15, top + t1 + 65)); e.Graphics.DrawString(strJobSalary, conFont, myBrush, new Point(left + k1 * 4 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("正常上班", headFont, myBrush, new Point(left + k1 * 5 + 15, top + 65)); e.Graphics.DrawString("天數(天)", headFont, myBrush, new Point(left + k1 * 5 + 15, top + t1 + 65)); e.Graphics.DrawString(WorkNumberDay, conFont, myBrush, new Point(left + k1 * 5 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("加班時間", headFont, myBrush, new Point(left + k1 * 6 + 15, top + 65)); e.Graphics.DrawString("天數(天)", headFont, myBrush, new Point(left + k1 * 6 + 15, top + t1 + 65)); e.Graphics.DrawString(OverNumberDay, conFont, myBrush, new Point(left + k1 * 6 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("加班費", headFont, myBrush, new Point(left + k1 * 7 + 15, top + t1 + 65)); e.Graphics.DrawString(OverDuty, conFont, myBrush, new Point(left + k1 * 7 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("浮動津貼", headFont, myBrush, new Point(left + k1 * 8 + 15, top + t1 + 65)); e.Graphics.DrawString(WorkSalary, conFont, myBrush, new Point(left + k1 * 8 + 15, top + t1 + t2 + 65)); e.Graphics.DrawString("總月薪", headFont, myBrush, new Point(left + k1 * 9 + 15, top + t1 + 65)); e.Graphics.DrawString(TotalSalary, conFont, myBrush, new Point(left + k1 * 9 + 15, top + t1 + t2 + 65)); //繪制第二個表格12列3行) e.Graphics.DrawRectangle(mypen, left, top + 200, 780, 125);//绘制矩形框 e.Graphics.DrawLine(mypen, left + k2, top + 200, left + k2, top + 325);//绘制第1列网格线 e.Graphics.DrawLine(mypen, left + k2 * 2, top + 200, left + k2 * 2, top + 325);//绘制第2列网格线 e.Graphics.DrawLine(mypen, left + k2 * 3, top + 200, left + k2 * 3, top + 325);//绘制第3列网格线 e.Graphics.DrawLine(mypen, left + k2 * 4, top + 200, left + k2 * 4, top + 325);//绘制第4列网格线 e.Graphics.DrawLine(mypen, left + k2 * 5, top + 200, left + k2 * 5, top + 325);//绘制第5列网格线 e.Graphics.DrawLine(mypen, left + k2 * 6, top + 200 + t1, left + k2 * 6, top + 325);//绘制第6列网格线 e.Graphics.DrawLine(mypen, left + k2 * 7, top + 200, left + k2 * 7, top + 325);//绘制第7列网格线 e.Graphics.DrawLine(mypen, left + k2 * 8, top + 200, left + k2 * 8, top + 325);//绘制第8列网格线 e.Graphics.DrawLine(mypen, left + k2 * 5, top + 200 + t1, left + k2 * 7, top + 200 + t1);//绘制第1行网格线 e.Graphics.DrawLine(mypen, left + k2 * 9, top + 200 + t1, left + k2 * 9, top + 325);//绘制第9列网格线 e.Graphics.DrawLine(mypen, left + k2 * 10, top + 200 + t1, left + k2 * 10, top + 325);//绘制第10列网格线 e.Graphics.DrawLine(mypen, left + k2 * 11, top + 200 + t1, left + k2 * 11, top + 325);//绘制第11列网格线 e.Graphics.DrawLine(mypen, left + k2 * 12, top + 200, left + k2 * 12, top + 325);//绘制第12列网格线 e.Graphics.DrawLine(mypen, left + k2 * 8, top + 200 + t1, left + k2 * 12, top + 200 + t1);//绘制第1行网格线 e.Graphics.DrawLine(mypen, left, top + 200 + t1 + t2, 795, top + 200 + t1 + t2);//绘制第2行网格线 //第二個表標題 backNumberDay e.Graphics.DrawString("缺勤天", headFont, myBrush, new Point(left + 10, top + 200 + 15)); e.Graphics.DrawString("數(天)", headFont, myBrush, new Point(left + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(backNumberDay, conFont, myBrush, new Point(left + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("加點時", headFont, myBrush, new Point(left + k2 + 10, top + 200 + 15)); e.Graphics.DrawString("時(小時)", headFont, myBrush, new Point(left + k2 + 10, top + 200 + t1 + 15));//加班時間(小時) e.Graphics.DrawString(OverTime, conFont, myBrush, new Point(left + k2 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("加班時", headFont, myBrush, new Point(left + k2 * 2 + 10, top + 200 + 15)); e.Graphics.DrawString("時(小時)", headFont, myBrush, new Point(left + k2 * 2 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString("法定假加", headFont, myBrush, new Point(left + k2 * 3 + 10, top + 200 + 15)); e.Graphics.DrawString("班(小時)", headFont, myBrush, new Point(left + k2 * 3 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(OverLawTime, conFont, myBrush, new Point(left + k2 * 3 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("缺勤扣除", headFont, myBrush, new Point(left + k2 * 4 + 10, top + 200 + 15)); e.Graphics.DrawString("/補年假", headFont, myBrush, new Point(left + k2 * 4 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(PublicTime, conFont, myBrush, new Point(left + k2 * 4 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("社會保險除扣除", headFont, myBrush, new Point(left + k2 * 5 + 10, top + 200 + 15)); e.Graphics.DrawString("養老保", headFont, myBrush, new Point(left + k2 * 5 + 10, top + 200 + t1 + 5)); e.Graphics.DrawString("險(8%)", headFont, myBrush, new Point(left + k2 * 5 + 10, top + 200 + t1 + 20)); e.Graphics.DrawString(WelfareFund, conFont, myBrush, new Point(left + k2 * 5 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("醫保", headFont, myBrush, new Point(left + k2 * 6 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(MedicalInsurance, conFont, myBrush, new Point(left + k2 * 6 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("住房公", headFont, myBrush, new Point(left + k2 * 7 + 10, top + 200 + 15)); e.Graphics.DrawString("金扣除", headFont, myBrush, new Point(left + k2 * 7 + 10, top + 200 + t1)); e.Graphics.DrawString("(5%)", headFont, myBrush, new Point(left + k2 * 7 + 10, top + 200 + t1 + 20)); e.Graphics.DrawString(HousingFund, conFont, myBrush, new Point(left + k2 * 7 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("個稅扣除", headFont, myBrush, new Point(left + k2 * 8 + 30, top + 200 + 15)); e.Graphics.DrawString("交稅基數", headFont, myBrush, new Point(left + k2 * 8 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(HousingFund, conFont, myBrush, new Point(left + k2 * 8 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("稅率", headFont, myBrush, new Point(left + k2 * 9 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(strTax, conFont, myBrush, new Point(left + k2 * 9 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("扣除數", headFont, myBrush, new Point(left + k2 * 10 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(strClerkSalary, conFont, myBrush, new Point(left + k2 * 10 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("代扣個稅", headFont, myBrush, new Point(left + k2 * 11 + 10, top + 200 + t1 + 15)); e.Graphics.DrawString(strClerkSalary, conFont, myBrush, new Point(left + k2 * 11 + 10, top + 200 + t1 + t2 + 15)); e.Graphics.DrawString("實發工資", headFont, myBrush, new Point(left + k2 * 12 + 10, top + 200 + 25)); e.Graphics.DrawString(strSalary, conFont, myBrush, new Point(left + k2 * 12 + 10, top + 200 + t1 + t2 + 15)); //bottom e.Graphics.DrawString("發薪日期:" + DateTime.Now.ToLongDateString(), new Font("宋体", 7), myBrush, new Point(right + 150, top + 330)); } catch (DirectoryNotFoundException ex) { ex.Message.ToString(); } } /// <summary> /// 打印 /// 塗聚文 /// 締友計算機信息技術有限公司 /// Geovin Du /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { //A4紙:页面宽度 827* 1169 (英寸),210*297(毫米) //自定義紙張大小 PaperSize pkCustomSize = new PaperSize( "custom size",(int)(82.55*100/25.4+1),(int)(184.0*100/25.4+1)); //毫米轉英寸 PaperSize pkCustomSize = new PaperSize("Custum", (int)(216 * 100 / 25.4 + 1), (int)(97 * 100 / 25.4 + 1)); //六福的工資單規格 this.printDocument1.DefaultPageSettings.PaperSize = pkCustomSize; int width = (int)(216 * 100 / 25.4 + 1); int height = (int)(97 * 100 / 25.4 + 1); //this.printDocument1.DefaultPageSettings.PaperSize.Height = height; //this.printDocument1.DefaultPageSettings.PaperSize.Width = width; //PageSettings storePageSetting = new PageSettings();//实列化一个对PageSettings对象 //foreach (PaperSize ps in printDocument1.PrinterSettings.PaperSizes)//查找当前设置纸张 //{ // if (paperName == ps.PaperName) // { // storePageSetting.PaperSize = ps; // break; // } //} foreach (PaperSize paperSize in printDocument1.PrinterSettings.PaperSizes) { if (paperSize.PaperName == "Custum" && paperSize.Height == width && paperSize.Height == height) { printDocument1.DefaultPageSettings.PaperSize = paperSize; break; } } printDocument1.DefaultPageSettings.Landscape = false;// //this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", 500, 300); printPreviewDialog1.ShowDialog(); }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)