本文介绍了如何在Windows窗体应用程序中的多个页面中打印数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.......
我想在Windows窗体应用程序中打印数据集。在我的数据集中有5行3列,我想每页打印两行 .means 将有3页打印整个数据集。我的代码是
Hi Everyone.......
I want to print a data-set in windows form application . In my dataset there are 5 rows and 3 columns , and i want to print two rows per pages .means there will be 3 pages to print whole data-set. My code is
float CurrentX = 20;//This is for X axis
float CurrentY = 100; //This is for Y axis
int linesPerPage = 2;
int count = 0;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
foreach (DataRow Dr in ds.Tables[0].Rows)
{
foreach (DataColumn dc in ds.Tables[0].Columns)
{
e.Graphics.DrawString(Dr[dc].ToString(), DefaultFont, Brushes.Black, CurrentX, CurrentY);
CurrentX = CurrentX + 50;//Increment of X axis by 50
}
CurrentY = CurrentY + 100;//Increment of Y axis by 100 for new row
CurrentX = 20; //Initialize the X axis for start the same position
count = count + 1;//Increment the count
if (count > linesPerPage)
{
e.HasMorePages = true;
}
else e.HasMorePages = false;
}
}
但是这里的页数达到无穷大且结果不会到来。实际上
e.HasMorePages逻辑没有清除给我,我尝试实现逻辑,但每次我失败。哪里有错误,请提出一些建议。
谢谢....
But here number of pages in going to infinity and result is not coming . actually
e.HasMorePages logic is not cleared to me, i try to implement the logic but every time i failed. Where is the mistake , please suggest some things .
Thank You....
推荐答案
Dim pageLine As Integer = 1
Dim lpp As Integer = CInt(Math.Floor((e.MarginBounds.Bottom - y) / 18))
For i As Integer = _curRow To _linesReq
Do While (pageLine <= lpp) And (_curRow <= _linesReq)
' Print some stuff
y += h
_curRow += 1
pageLine += 1
Loop
If (pageLine >= lpp) And (_curRow <= _linesReq) Then
page += 1
pageLine = 1
e.HasMorePages = True
Exit For
Else
e.HasMorePages = False
Exit For
End If
Next
这篇关于如何在Windows窗体应用程序中的多个页面中打印数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!