[quote]
The below code doesnot generate 2 pages. Can anyone help me what is wrong in the code.
[code]
public class PrintDetails : PrintDocument
{
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
Font fnt = new Font("Courier New", 10, FontStyle.Regular, GraphicsUnit.Point);
e.Graphics.DrawString("First Page",fnt,Brushes.Black,5,5);
e.HasMorePages=true;
e.Graphics.DrawString("Second Page",fnt,Brushes.Black,5,5);
fnt.Dispose();
e.HasMorePages=false;
}
}
problem with HasMorePagesHasMorePages property in C#.net
Page 1 of 1
1 Replies - 8304 Views - Last Post: 07 August 2006 - 08:19 PM
Replies To: problem with HasMorePages
#2
Re: problem with HasMorePages
Posted 07 August 2006 - 08:19 PM
suleh, on 3 Aug, 2006 - 04:13 AM, said:
The below code doesnot generate 2 pages. Can anyone help me what is wrong in the code.
public class PrintDetails : PrintDocument
{
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
Font fnt = new Font("Courier New", 10, FontStyle.Regular, GraphicsUnit.Point);
e.Graphics.DrawString("First Page",fnt,Brushes.Black,5,5);
e.HasMorePages=true;
e.Graphics.DrawString("Second Page",fnt,Brushes.Black,5,5);
fnt.Dispose();
e.HasMorePages=false;
}
}
OnPrintPage gets fired after every page being printed. You need to have a variable set for checking how many pages are left and set e.HasMorePages=true; before base.OnPrintPage(e);
int printedPages = 0;
int maxPages = 2;
protected override void OnPrintPage(PrintPageEventArgs e)
{
e.HasMorePages = printedPages == maxPages;
Font fnt = new Font("Courier New", 10, FontStyle.Regular, GraphicsUnit.Point);
e.Graphics.DrawString(printedPages.ToString(),fnt,Brushes.Black,5,5);
fnt.Dispose();
base.OnPrintPage(e);
}
or something like that, its been a long time since i've dealt with printing
This post has been edited by sontek: 07 August 2006 - 08:20 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|