/// <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();
}
分享到:
相关推荐
在“CSharp Com Port Print”这个主题中,我们主要关注的是如何使用C#通过串行通信(COM端口)进行打印操作。本文将深入探讨C#中的串口通信、打印机接口以及如何实现LPT并口打印测试。 首先,了解COM端口是理解这个...
在本案例中,"Csharp_datagrid-print_class.rar_csharp 打印"是指一个使用C#编写的类库,专门用于处理数据网格(DataGridView)的打印功能。DataGridView是Windows Forms中用于展示表格数据的强大控件,它允许用户...
void PrintName(string name) { Console.WriteLine(name); } ``` ###### 1.6.6.2 方法体与局部变量 方法体包含了执行代码。可以在方法体内声明局部变量。例如: ```csharp void DoSomething() { int x = 5; // ...
Learning CSharp Learning CSharp Learning CSharp Learning CSharp
标题中的“UHFReader18CSharp.rar_UHFREADER18CSharp_spiten5p”指的是一个关于UHF RFID阅读器(UHFReader18)的C#开发库资源,其中可能包含了针对该硬件设备的C#接口和示例代码。这个库可能是为了帮助开发者在C#...
Assembly-CSharp.dll
在本文中,我们将深入探讨C#(CSharp)中的串口通信程序,这是一个在嵌入式系统、自动化设备以及各种物联网(IoT)应用中广泛使用的通信技术。通过使用C#进行串口通信,开发者可以与硬件设备进行交互,接收或发送数据...
CSharp语言参考.CHMCSharp语言参考.CHMCSharp语言参考.CHMCSharp语言参考.CHMCSharp语言参考.CHM
csharp_精选实例
CSharp使用DLL进行调用MatLab混编 本文将详细介绍如何使用CSharp调用MatLab DLL,生成DLL库,并使用CSharp调用DLL,实现MatLab混编。 一、生成DLL库 在生成DLL库之前,需要进行函数准备和环境预设。函数准备是指...
介绍 这些文档包含编写一致,清晰,诱人的现代C#的准则。 如果您对此处的内容有任何疑问,请打开一个请求请求,其中包含您建议的更改,并包含支持和反对采用这些更改的论点; 解释您提议的变更的好处以及任何弊端...
绝对可用的c#打印源码,vs08下调过。 我也是因为客户需要打印奇怪的表单才搞的。 实现web界面下精确打印,利用system.Drawing,注意,不是简单的调用ie打印框,而是可以精确到每个单元格的打印,需要自己根据源码调整...
Microsoft.CSharp
《microsoft.csharp_dll在C# WPF开发中的重要角色》 在软件开发的世界里,Microsoft的.NET框架扮演着至关重要的角色,而其中的microsoft.csharp_dll则是.NET框架的一部分,专门为C#语言提供支持。这个动态链接库...
上海市计算机二级考试Csharp编程考试题目
标题中的“csharp-dotnet2-client-generated_csharp_Csharp_”暗示了这是一个针对C# .NET 2.0平台生成的客户端库,主要用于与某个Web服务进行交互。这个库可能是通过自动化工具,如Swagger Codegen,自动生成的,...
CSharp Language Specification C# 5.0高清中文版 PDF+WORD
unity3d加密解密Assembly-CSharp.dll解密。。。。。。。。
本压缩包中的"Csharp编程指南+参考手册"是一部全面介绍C#编程的资源,对于初学者和经验丰富的开发者都极具价值。这个文档通常会涵盖C#的基础概念、语法、类库和高级特性,包括但不限于以下内容: 1. **基础语法**:...