在这里只占源码供日后所用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace PrinterDemo {
class PrinterTest {
private DataTable theDGV; //用于接收包含打印内容的数据表
private string printTitle; //打印标题内容
private List<int> ColumnsWidth; //存储列宽
private List<int> ColumnsLeft;
private int totalWidth; //计算打印区域的总宽度;
private int RowHeaderHeight; //列标题的宽度
private int RowsHeight; //存储行高
private int pageNO; //当前打印页的序号
private int rowPoint; //当前打印行的序号
private bool newPage; //是否打印新页的标识
private int PageWidth;
private int PageHeight;
private int LeftMargin;
private int TopMargin;
private int RightMargin;
private int BottomMargin;
private StringFormat TitleFormat; //标题打印对齐格式
private StringFormat CellFormat; //表格打印对齐格式
private PrintDocument myDocument; //向打印机发送的输出对象
private Font theTitleFont; //标题字体
private Font printFont; //表格字体
public PrinterTest(PrintDocument document, DataTable DGV, string title, Font titleFont, Font printFont)
{
this.theDGV = DGV;
this.printTitle = title;
this.theTitleFont = titleFont;
this.printFont = printFont;
this.myDocument = document;
myDocument.OriginAtMargins = true;//指定绘图操作从页边距内开始算起
ColumnsWidth = new List<int>();
ColumnsLeft = new List<int>();
}
//计算打印参数。包括预打印表格的原始宽度,打印高度宽度
public void print_Calculate(Graphics g)
{
totalWidth =0;
SizeF tmpSize = new SizeF();
float tmpWidth;
//MessageBox.Show(printFont.ToString());
for (int i = 0; i < theDGV.Columns.Count; i++)
{
tmpSize = g.MeasureString(theDGV.Columns[i].ColumnName, printFont);
tmpWidth = tmpSize.Width;
Ro