problem with HasMorePages

HasMorePages property in C#.net

Page 1 of 1

1 Replies - 8659 Views - Last Post: 07 August 2006 - 08:19 PM Rate Topic: -----

#1 suleh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-July 06

problem with HasMorePages

Posted 03 August 2006 - 04:13 AM

[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;
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: problem with HasMorePages

#2 sontek  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 283
  • Joined: 13-September 01

Re: problem with HasMorePages

Posted 07 August 2006 - 08:19 PM

View Postsuleh, 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1