前几天发现一个超好用的打印类。无敌好用,爽得我啊~。
原文出处:http://www.zu14.cn/2010/01/30/dotnet-csharp-winform-print-datagridview/
使用方式:直接调用 PrintDGV.Print_DataGridView(this.dataGridView1)
打印时会跳出一个简单的打印设置:
打印效果:
由于这个打印效果还是有点不符合客户的需求,所以就做了一些改动,下面的这个打印类的一些说明:
1、打印内容右对齐:PrintDoc_BeginPrint()函数
StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Near;
// StrFormat.Alignment = StringAlignment.Far;这句是右对齐的效果
StrFormat.LineAlignment = StringAlignment.Center;
StrFormat.Trimming = StringTrimming.EllipsisCharacter;
2、加个报表尾PrintDoc_PrintPage()函数末尾
string PageNum = "贷款种类:汽车销费贷款 年限:" + Y + "期 利率:" + Lilv + "‰";
e.Graphics.DrawString(PageNum, dgv.Font, Brushes.Black,e.MarginBounds.Left + (e.MarginBounds.Width -e.Graphics.MeasureString(PageNum, dgv.Font,e.MarginBounds.Width).Width) / 2, e.MarginBounds.Top/4+tmpTop );
string PageNum2 = "本金:" + Bj + "元 利息:" + Lixi + "元 本息合计:" + Bxhj + "元";
e.Graphics.DrawString(PageNum2, dgv.Font, Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(PageNum, dgv.Font, e.MarginBounds.Width).Width) / 2, e.MarginBounds.Top / 2 + tmpTop);
效果如图: