datagridviwe打印类

前几天发现一个超好用的打印类。无敌好用,爽得我啊~。偷笑

原文出处: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);

效果如图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值