printout multiple pages

using hasmorepages but cannot printout

Page 1 of 1

6 Replies - 8786 Views - Last Post: 27 January 2010 - 09:44 AM Rate Topic: -----

#1 matyus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-February 09

printout multiple pages

Post icon  Posted 31 December 2009 - 12:20 AM

hi, to printpreview multiple pages,we can use hasmorepages.. but how to printout multiple pages?

my program can printpreview multiple pages,then when i try to printout them, my printer only roll a paper but nothing be printed..
Is This A Good Question/Topic? 0
  • +

Replies To: printout multiple pages

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: printout multiple pages

Posted 31 December 2009 - 12:57 AM

Hi,

What do you have so far?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2256
  • View blog
  • Posts: 9,444
  • Joined: 29-May 08

Re: printout multiple pages

Posted 31 December 2009 - 11:02 PM

Have a look at the following threads.
e.HasMorePages and Logic to use it
Help with "hasmorepages" please.

Tutorial: Printing In vb.net
Was This Post Helpful? 0
  • +
  • -

#4 matyus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-February 09

Re: printout multiple pages

Posted 17 January 2010 - 11:12 PM

sory, this is my code :

Dim PageNumber as Integer = 0

Private Sub PrintDoc2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc2.PrintPage
	Dim ReportFont As New Font("Arial", 12, FontStyle.Regular)
	Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
	Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
	Dim TextString As String

	Select Case PageNumber
	Case 0
		TextString = "ABC"
		e.Graphics.DrawString(TextString, reportFont,Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
		e.HasMorePages = True
	Case 1
		TextString = "XYZ"
		e.Graphics.DrawString(TextString, reportFont,Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
		e.HasMorePages = False
	   
	End Select
	PageNumber += 1
End Sub



it shows 2 pages in printpreview, but when i click print in the printpreview, my printer print nothing,just rolling the paper..
why?
Was This Post Helpful? 0
  • +
  • -

#5 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: printout multiple pages

Posted 18 January 2010 - 06:49 AM

Hi,

You can try this:

Dim PageNumber as Integer = 0

Private Sub PrintDoc2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc2.PrintPage
	Dim ReportFont As New Font("Arial", 12, FontStyle.Regular)
	Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
	Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
	Dim TextString As String

	Select Case PageNumber
	Case 0
		TextString = "ABC"
				e.HasMorePages = True
	Case 1
		TextString = "XYZ"
			   e.HasMorePages = False
	   
	End Select
	PageNumber += 1
	 e.Graphics.DrawString(TextString, reportFont, Brushes.Black,	HorizontalPrintLocationSingle, VerticalPrintLocationSingle)

End Sub

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: printout multiple pages

Posted 18 January 2010 - 08:13 AM

Matyus,
The printpreview is essentially printing the document to the screen. When this is done you are at the end of your counter. What you will need to do is reset your counter. This can be done in the BeginPrint method of your PrintDoc2

Try adding this code:
	Private Sub PrintDoc2_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc2.BeginPrint
		PageNumber = 0
	End Sub



I guess I should add:

You are using a public variable to keep track of the pages. In your code you are checking to see if the value is 0 or 1 and printing accordingly. When you show the print preview dialog the counter increments and displays both pages.

Then when you click the print button the counter still being 2 does not find anything true in the select case statements. This is why you have to reset it in the BeginPrint method. It just keeps incrementing.

This post has been edited by CharlieMay: 18 January 2010 - 08:33 AM

Was This Post Helpful? 1
  • +
  • -

#7 matyus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 22-February 09

Re: printout multiple pages

Posted 27 January 2010 - 09:44 AM

View PostCharlieMay, on 18 Jan, 2010 - 07:13 AM, said:

Matyus,
The printpreview is essentially printing the document to the screen. When this is done you are at the end of your counter. What you will need to do is reset your counter. This can be done in the BeginPrint method of your PrintDoc2

Try adding this code:
	Private Sub PrintDoc2_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDoc2.BeginPrint
		PageNumber = 0
	End Sub



I guess I should add:

You are using a public variable to keep track of the pages. In your code you are checking to see if the value is 0 or 1 and printing accordingly. When you show the print preview dialog the counter increments and displays both pages.

Then when you click the print button the counter still being 2 does not find anything true in the select case statements. This is why you have to reset it in the BeginPrint method. It just keeps incrementing.


thanks CharlieMay..~~! its really work! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1