打印不在列表中的页面
Print pages NOT in the List
我有一个 int
列表,其中包含我 不想 想要打印的页面。
我们称它为skipPages
。
当我尝试将实际打印部分放入 if(skipPages.IndexOf(currentPage)<0)
语句时,它打印出空白页。
public void printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
List<int> skipPages = new List<int> { 2, 5, 6 };
if(currentPage<totalPage) e.HasMorePages = true;
else e.HasMorePages = false;
if(skipPages.IndexOf(currentPage)<0)
{
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
}
currentPage++;
}
当我尝试将 e.HasMorePages = true
放入其中时,它只会在第一个跳过页面后停止一切。
public void printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
List<int> skipPages = new List<int> { 2, 5, 6 };
if(currentPage<totalPage && skipPages.IndexOf(currentPage)<0) e.HasMorePages = true;
else e.HasMorePages = false;
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
currentPage++;
}
有人可以教我如何正确设置吗?
非常感谢!!!
每页都会触发 PrintPage 事件,因此您只需跳过列表中的 currentPage
。
您还需要一种机制来检查最后几页是否在跳过列表中,以避免最后打印空白页。
List<int> skipPages = new List<int> { 2, 5, 6 };
private void printDocument1_BeginPrint(object sender, PrintEventArgs e)
{
currentPage = 0;
}
public void printPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
bool f = false;
int c = currentPage + 1;
//Mechanism to check for the last few pages.
while(skipPages.IndexOf(c)>=0) c++;
if(c>=totalPages) f=false;
else f=true;
while(skipPages.IndexOf(currentPage)>=0) currentPage++; //Actual skipping part.
if(currentPage<totalPage-1) e.HasMorePages = f;
else e.HasMorePages = false;
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
currentPage++;
}
我有一个 int
列表,其中包含我 不想 想要打印的页面。
我们称它为skipPages
。
当我尝试将实际打印部分放入 if(skipPages.IndexOf(currentPage)<0)
语句时,它打印出空白页。
public void printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
List<int> skipPages = new List<int> { 2, 5, 6 };
if(currentPage<totalPage) e.HasMorePages = true;
else e.HasMorePages = false;
if(skipPages.IndexOf(currentPage)<0)
{
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
}
currentPage++;
}
当我尝试将 e.HasMorePages = true
放入其中时,它只会在第一个跳过页面后停止一切。
public void printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
List<int> skipPages = new List<int> { 2, 5, 6 };
if(currentPage<totalPage && skipPages.IndexOf(currentPage)<0) e.HasMorePages = true;
else e.HasMorePages = false;
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
currentPage++;
}
有人可以教我如何正确设置吗?
非常感谢!!!
每页都会触发 PrintPage 事件,因此您只需跳过列表中的 currentPage
。
您还需要一种机制来检查最后几页是否在跳过列表中,以避免最后打印空白页。
List<int> skipPages = new List<int> { 2, 5, 6 };
private void printDocument1_BeginPrint(object sender, PrintEventArgs e)
{
currentPage = 0;
}
public void printPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
bool f = false;
int c = currentPage + 1;
//Mechanism to check for the last few pages.
while(skipPages.IndexOf(c)>=0) c++;
if(c>=totalPages) f=false;
else f=true;
while(skipPages.IndexOf(currentPage)>=0) currentPage++; //Actual skipping part.
if(currentPage<totalPage-1) e.HasMorePages = f;
else e.HasMorePages = false;
e.Graphics.DrawString(
currentPage.ToString(),
new Font("Times New Roman",12),
new SolidBrush(Color.Black),
new Point(10,10));
currentPage++;
}