Hi,

I do have another doubt. The thing is in my project done in VB.NET and MSQL as back end...I need to print multiple pages.

I can print only the page that is displayed on the VB.NET form ie the datas displayed on the VB.NET form.

But it has more than 3 pages and each time I print it prints the same page again and again.

I used "HasMorePages" in the PageEvent of the Printerdocument and i don't know its not working.

Anyone help me as am new to this.

Thanks so much

B.H

Printing in .NET is funky, but simple. Once you get the hang of it it's no problem, but that first hurdle is figuring out how the heck the parts all fit together. Printing multiple pages is handled inside the PrintPage event handler. The handler selects which page to print and also notifies the print controller whether more pages exist with e.HasMorePages. Let's say you get your info from records in a data table. You could use a Page variable as an index into the data table, and when it reaches MaxPages, you set e.HasMorePages to false. My VB is kind of weak right now, so here's some C#:

private int _page;
private int _maxPage;
private PrintPreviewDialog _preview = new PrintPreviewDialog();
private PrintDocument _document = new PrintDocument();

public MyClass()
{
  //...
  _document.PrintPage += PrintPage_Handler;
}

public void PrintAll()
{
  _page = 0;
  _maxPage = _dtMaster.Rows.Count;
  _preview.Document = _document;
  _preview.ShowDialog();
}

private void PrintPageHandler( object sender, PrintPageEventArgs e )
{
  // Get info to print (name, address)
  string name = (string)_dtMaster[_page]["Name"];
  string addr = (string)_dtMaster[_page]["Address"];

  // Draw the strings
  //...

  e.HasMorePages = ++_page < _maxPage;
}

Using the preview dialog instead of the print dialog will save you paper while testing. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.