在每一页上打印标题c#
我有5个索引的列表,我想在一个新的页面上打印标题,我应该写些什么,以便它在下一页上打印在每一页上打印标题c#,c#,printing,C#,Printing,我有5个索引的列表,我想在一个新的页面上打印标题,我应该写些什么,以便它在下一页上打印 list<> // 5 indices void printDocument_PrintPage(object sender, PrintPageEventArgs e) { Graphics graphic = e.Graphics; float fontHeight = font.GetHeight(); int startX = 10; int star
list<> // 5 indices
void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphic = e.Graphics;
float fontHeight = font.GetHeight();
int startX = 10;
int startY = 10;
for (int i = 0; i < list.Count; i++)
{
graphic.DrawString(list[i].Title, new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY);
}
}
list//5个索引
无效打印文档\u打印页(对象发送者,PrintPageEventArgs e)
{
图形=e.图形;
float fontHeight=font.GetHeight();
int startX=10;
int startY=10;
for(int i=0;i
您必须维护一个实例变量,该变量指向列表中要显示的项的当前索引,并在每次打印页面时递增该变量
int currIndex = 0;
void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphic = e.Graphics;
float fontHeight = font.GetHeight();
int startX = 10;
int startY = 10;
graphic.DrawString(list[currIndex++].Title, new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY);
if(currIndex == list.Count)
{
e.HasMorePages = false;
currIndex = 0;
}
else
{
e.HasMorePages = true;
}
}
printDocument对象为每个页面调用相同的PrintPage()方法。如果希望不同的内容显示在不同的页面上,则需要该方法之外的代码来存储当前状态,并且需要该方法内的代码来检查该状态,并根据存储在该方法之外的状态恢复/继续打印 如果PrintPage()中有打印标题的说明,则将打印标题。故事结束了