int linesPerPage = 75;//75行每页
int lineNo = 0;//存放当前要打印行的行号
int lineQty; //存放总共要打印的行数,可以是一个估算值,略大于实际行数
int printingPageNo = 0; //当前打印的页号
int count = 0; //当前页的行数计数
public static void printerpage(PrintPageEventArgs e)
{
string line6 = "-----------------------------------------------------------";
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
StringFormat drawFormat1 = new StringFormat();
drawFormat1.FormatFlags = StringFormatFlags.DisplayFormatControl;
x = 2;
y =0;
if (!e.HasMorePages)
{
ds = dbTotal.QueryData("select * from Billlist where stant = 'takeaway'", "list");
y = y + 10;
e.Graphics.DrawString("No", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y, drawFormat1);
x = x + 45;
e.Graphics.DrawString("TbNo", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 75;
e.Graphics.DrawString("Time", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 130;
y = y + 20;
lineQty = ds.Tables["list"].Rows.Count + 5;
}
while (count < linesPerPage && lineNo < lineQty)
{
if (lineNo < ds.Tables["list"].Rows.Count) //由于lineNo用于表中的下标值,因此需要加上该判断
{
string no = ds.Tables["list"].Rows[lineNo][7].ToString();
string tabno = ds.Tables["list"].Rows[lineNo][5].ToString();
string time = ds.Tables["list"].Rows[lineNo][3].ToString().Substring(0, 10);
string tolprice = ds.Tables["list"].Rows[lineNo][1].ToString();
e.Graphics.DrawString(no, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat1);
x = x + 50;
e.Graphics.DrawString(tabno, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString(time, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 150;
e.Graphics.DrawString(tolprice,new Font("verdana",8,FontStyle.Regular),Brushes.Black,x,y)
x = 2;
y = y + 15;
count++;
}
lineNo++;
}
if (lineQty > lineNo)
{
e.HasMorePages = true;
count = 0;
printingPageNo++;
circle = 0;
}
else
{
e.Graphics.DrawString(line6, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y);//----- 线
count++;
e.HasMorePages = false;
}
}分页打印,页是分了,但就是打在第一页
int lineNo = 0;//存放当前要打印行的行号
int lineQty; //存放总共要打印的行数,可以是一个估算值,略大于实际行数
int printingPageNo = 0; //当前打印的页号
int count = 0; //当前页的行数计数
public static void printerpage(PrintPageEventArgs e)
{
string line6 = "-----------------------------------------------------------";
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
StringFormat drawFormat1 = new StringFormat();
drawFormat1.FormatFlags = StringFormatFlags.DisplayFormatControl;
x = 2;
y =0;
if (!e.HasMorePages)
{
ds = dbTotal.QueryData("select * from Billlist where stant = 'takeaway'", "list");
y = y + 10;
e.Graphics.DrawString("No", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y, drawFormat1);
x = x + 45;
e.Graphics.DrawString("TbNo", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 75;
e.Graphics.DrawString("Time", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 130;
y = y + 20;
lineQty = ds.Tables["list"].Rows.Count + 5;
}
while (count < linesPerPage && lineNo < lineQty)
{
if (lineNo < ds.Tables["list"].Rows.Count) //由于lineNo用于表中的下标值,因此需要加上该判断
{
string no = ds.Tables["list"].Rows[lineNo][7].ToString();
string tabno = ds.Tables["list"].Rows[lineNo][5].ToString();
string time = ds.Tables["list"].Rows[lineNo][3].ToString().Substring(0, 10);
string tolprice = ds.Tables["list"].Rows[lineNo][1].ToString();
e.Graphics.DrawString(no, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat1);
x = x + 50;
e.Graphics.DrawString(tabno, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString(time, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 150;
e.Graphics.DrawString(tolprice,new Font("verdana",8,FontStyle.Regular),Brushes.Black,x,y)
x = 2;
y = y + 15;
count++;
}
lineNo++;
}
if (lineQty > lineNo)
{
e.HasMorePages = true;
count = 0;
printingPageNo++;
circle = 0;
}
else
{
e.Graphics.DrawString(line6, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y);//----- 线
count++;
e.HasMorePages = false;
}
}分页打印,页是分了,但就是打在第一页
解决方案 »
- WPF如何实现:当MouseOver的时候,可以让image突起?
- C# 怎么打开新建网页啊
- 提示信息需要维护吗??
- 单例对象
- 请问 怎样将EXCEL表格嵌入C#中 并进行操作啊?
- listview 选中一行并把对应的几列数据放到textbox中.
- 解码
- asp.net 数据库系统并发问题,如何解决
- 索引超出了数组界限 大家里看看
- System.IO.FileNotFoundException 未能加载文件或程序集“System.Windows.Interactivity, Version
- 如何获取多表查询的表结构信息?
- c# winform 画图程序,只要一个类似windows画图中画刷功能的东西,画完能保存图片就行
好像不会执行啊
while (count < linesPerPage && lineNo < lineQty)
你这样进行循环
会执行啊,要不怎么会回过来把第2页也打在第一页呢?
while (count < linesPerPage && lineNo < lineQty)
这个循环是这样,当每页count行数 比75小,说明还在一页;lineNo < lineQty则代表 lineNo是表里的行数比要打印的行数小。 都成立就循环啊
然后2页就都打在第一页
this.printDS.Tables[0].Rows.RemoveAt(i);
if(this.printDS.Tables[0].Rows.Count > 0)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
} (2) 打印一下页前
Graphics.Clear()
if (lineQty > lineNo)应该是以上的两个地方出的问题。
我解决了,但是自己想不通的。我是将循环放到if(!e.HasMorePages)这个条件里。其实我单步跟踪发现每打一页都要进2次printpage。然后e.HasMorePages状态就自己变成false了。哎~~再研究研究。谢谢你
{
e.HasMorePages = true;
count = 0;
printingPageNo++;
circle = 0;
}
else
{
e.Graphics.DrawString(line6, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y);//----- 线
count++;
e.HasMorePages = false;
}