PrintDocument ,为什么预览时看到有数据,打印出来却是空白 如题 望各位大虾帮忙解决。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataTable dtPrintInfo; //存放要打印的信息private int lineNo; //存放当前要打印行的行号private int lineQty; //存放总共要打印的行数,可以是一个估算值,略大于实际行数private int printingPageNo; //预览发货单 在这里打出来是没有数据的 private void button1_Click(object sender, EventArgs e) { //如果这三个参数不设为0时将会出现第二打印不成功; this.lineNo = 0; this.lineQty = 0; printingPageNo = 0; //dt = GetPrintDataTable(); this.printPreviewDialog_all.Document = this.printDocument_all; printPreviewDialog_all.ShowDialog(); //printDocument_all. }//打印控件 这里打印有数据 private void btn_fahuo_Click(object sender, EventArgs e) { printDocument_all.Print(); }//这里是printPage事件private void printDocument_all_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { dtPrintInfo = GetPrintDataTable();//dt;//DXTBEX.BFL.Trade_StructBFL.Instance.GetList("").Tables[0]; //dtPrintInfo = datagv_all.DataSource as DataTable; //DXTBEX.BFL.Trade_StructBFL.Instance.GetList(""); string strLine;//用于存放当前行打印的信息 float leftMargin = (e.MarginBounds.Left) * 3 / 4; //左边距 float topMargin = e.MarginBounds.Top * 2 / 3; //顶边距 float verticalPosition = topMargin; //初始化垂直位置,设为顶边距 Font mainFont = new Font("宋体", 10, FontStyle.Regular);//打印的字体 Font tfont = new Font("宋体", 20, FontStyle.Bold); //每页的行数,当打印行数超过这个时,要换页(1.05这个值是根据实际情况中设定的,可以不要) int linesPerPage = (int)(e.MarginBounds.Height * 1.05 / 400);//mainFont.GetHeight(e.Graphics) #region if (printingPageNo == 0) //打印第一页时,需要打印以下头信息 { lineQty = dtPrintInfo.Rows.Count + 15; } #endregion int count = 0; while (count < linesPerPage && lineNo < this.lineQty) { if (lineNo < dtPrintInfo.Rows.Count) //由于lineNo用于表中的下标值,因此需要加上该判断 { //打印内容 e.Graphics.DrawString(dtPrintInfo.Rows[lineNo]["buyer_nick"].ToString(), mainFont, Brushes.Black, leftMargin, verticalPosition, new StringFormat()); verticalPosition = (verticalPosition + mainFont.GetHeight(e.Graphics)) + 400;//每打印一行数据后新增加的距离; count++; } lineNo++; } //如果总行数大于目前实际行号,表明还有页要打,lineQty是估计数,因此实际用时要仔细估算 if (lineQty > lineNo) { e.HasMorePages = true; } else { e.Graphics.Dispose(); e.HasMorePages = false; } printingPageNo++; } 好象你的打印被注释掉了private void button1_Click(object sender, EventArgs e) { //如果这三个参数不设为0时将会出现第二打印不成功; this.lineNo = 0; this.lineQty = 0; printingPageNo = 0; //dt = GetPrintDataTable(); this.printPreviewDialog_all.Document = this.printDocument_all; printPreviewDialog_all.ShowDialog(); //printDocument_all.//////////去掉这里的注释试试能不能打出白纸? } private void button1_Click(object sender, EventArgs e) { //如果这三个参数不设为0时将会出现第二打印不成功; this.lineNo = 0; this.lineQty = 0; printingPageNo = 0; //dt = GetPrintDataTable(); this.printPreviewDialog_all.Document = this.printDocument_all; if(printPreviewDialog_all.ShowDialog() == DialogResult.OK)//判断一下 { printDocument_all.print();//如果单击了预览对话框的确定键就打印 }} 小妹请教读取XML节点的属性、值问题。 c#截取字符串 重复怎么弄? [Serializable]是什么意思呀? 如何实现将TREEVIEW控件绑定到DATAGRIDVIEW控件的单元格中? 数组元素大小排列问题 帮忙讲讲这个代码好吗 谢谢 C#中要显示一些柱图啊,饼图啊.有这样的控件吗? 怎么实现 自动提示栏,像JBuilder和Vc那样的 C#和串口控件MSCOMM32的问题 rzhou(海盗) 收分来 怎样增加一个gsyid=5的值作为listbox的默认值? 大家快帮帮忙吧
private int lineNo; //存放当前要打印行的行号
private int lineQty; //存放总共要打印的行数,可以是一个估算值,略大于实际行数
private int printingPageNo;
//预览发货单 在这里打出来是没有数据的
private void button1_Click(object sender, EventArgs e)
{
//如果这三个参数不设为0时将会出现第二打印不成功;
this.lineNo = 0;
this.lineQty = 0;
printingPageNo = 0;
//dt = GetPrintDataTable();
this.printPreviewDialog_all.Document = this.printDocument_all;
printPreviewDialog_all.ShowDialog();
//printDocument_all.
}//打印控件 这里打印有数据
private void btn_fahuo_Click(object sender, EventArgs e)
{
printDocument_all.Print();
}
//这里是printPage事件
private void printDocument_all_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
dtPrintInfo = GetPrintDataTable();//dt;//DXTBEX.BFL.Trade_StructBFL.Instance.GetList("").Tables[0];
//dtPrintInfo = datagv_all.DataSource as DataTable; //DXTBEX.BFL.Trade_StructBFL.Instance.GetList("");
string strLine;//用于存放当前行打印的信息
float leftMargin = (e.MarginBounds.Left) * 3 / 4; //左边距
float topMargin = e.MarginBounds.Top * 2 / 3; //顶边距
float verticalPosition = topMargin; //初始化垂直位置,设为顶边距 Font mainFont = new Font("宋体", 10, FontStyle.Regular);//打印的字体
Font tfont = new Font("宋体", 20, FontStyle.Bold); //每页的行数,当打印行数超过这个时,要换页(1.05这个值是根据实际情况中设定的,可以不要)
int linesPerPage = (int)(e.MarginBounds.Height * 1.05 / 400);//mainFont.GetHeight(e.Graphics) #region
if (printingPageNo == 0) //打印第一页时,需要打印以下头信息
{
lineQty = dtPrintInfo.Rows.Count + 15;
}
#endregion int count = 0; while (count < linesPerPage && lineNo < this.lineQty)
{
if (lineNo < dtPrintInfo.Rows.Count) //由于lineNo用于表中的下标值,因此需要加上该判断
{
//打印内容
e.Graphics.DrawString(dtPrintInfo.Rows[lineNo]["buyer_nick"].ToString(), mainFont, Brushes.Black, leftMargin, verticalPosition, new StringFormat());
verticalPosition = (verticalPosition + mainFont.GetHeight(e.Graphics)) + 400;//每打印一行数据后新增加的距离;
count++;
}
lineNo++;
} //如果总行数大于目前实际行号,表明还有页要打,lineQty是估计数,因此实际用时要仔细估算
if (lineQty > lineNo)
{
e.HasMorePages = true;
}
else
{
e.Graphics.Dispose();
e.HasMorePages = false;
} printingPageNo++; }
private void button1_Click(object sender, EventArgs e)
{
//如果这三个参数不设为0时将会出现第二打印不成功;
this.lineNo = 0;
this.lineQty = 0;
printingPageNo = 0;
//dt = GetPrintDataTable();
this.printPreviewDialog_all.Document = this.printDocument_all;
printPreviewDialog_all.ShowDialog();
//printDocument_all.//////////去掉这里的注释试试能不能打出白纸?
}
{
//如果这三个参数不设为0时将会出现第二打印不成功;
this.lineNo = 0;
this.lineQty = 0;
printingPageNo = 0;
//dt = GetPrintDataTable();
this.printPreviewDialog_all.Document = this.printDocument_all;
if(printPreviewDialog_all.ShowDialog() == DialogResult.OK)//判断一下
{
printDocument_all.print();//如果单击了预览对话框的确定键就打印
}
}