Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The printer button on the PrintPreviewDialog1 doesn't work. I have my report up in preview mode and I want to be able to click the little printer button (printer icon) in the top left of the print preview control and have the report that is being previewed, print. It doesn't. What I get is very strange. If the report has three pages what prints is a 4th page with just headings. Of course I don't want this page, I want the three pages of the report.

I've done a lot of googling and searching as I believe others must have had, and solved, this problem but I can't find any answers.

If I have to put code 'behind' the button I know the code to put there (m_PrintDocument.Print()). I just don't know how to put this code 'behind' this button.

Any guidance would be greatly appreciated.
Posted

Did you already try it a printdialog where you can select the printer.

VB
'Allow the user to choose a printer and specify other settings.
Dim dlgPrint As New PrintDialog

With dlgPrint
    .Document = Me.Document
    .AllowSelection = False
    .ShowNetwork = False
    .AllowCurrentPage = True
    .AllowSomePages = True
End With

'If the user clicked OK, print the document.
If dlgPrint.ShowDialog = Windows.Forms.DialogResult.OK Then
    Me.Document.Print()
End If
 
Share this answer
 
Comments
kentuckyjoe 26-Aug-12 17:55pm    
I've been unable to determine where to put this code. I have a print dialog control but that is where the button is that won't work. I don't think there is anything left for me to try. I'm sure the code is good; I just don't know where it goes.
I was hoping that there would be some way to place code behind that printer button but I guess there is not. Another, better solution, would be for microsoft to make that button work and print what it being previewed. That it doesn't do this already is pretty mindblowing. So, I'm not sure there is any solution. So, my intent is to close this question. Thank you.
 
Share this answer
 
If you are driving the print output as a report, you must be prepared to start the report over.

For example, A text file being printed must be reset to the beginning of the file at the end of the preview.

My language is avr so I hope this makes sense.

The sr, stream reader, is closed at the end of the preview.
e.HasMorePages = *false
sr.Close()

The preview print button calls the Printpage event again. The text file
is reopened to the beginning.
VB
BegSr printDocument1_PrintPage Access(*Private) Event(*this.printDocument1.PrintPage)
		DclSrParm sender *Object
		DclSrParm e System.Drawing.Printing.PrintPageEventArgs
	
		dclfld pinx  *integer2
		if currentindex = 0
			sr = *New System.IO.StreamReader(BarCd_FileName) 
		endif
		pinx = 0
		do fromval(0) toval(50-1) index(pinx)
			if sr.Peek() < 0
				leave
			endif	
			OsFileLine = sr.ReadLine()
			if OsFileLine = *nothing
				iterate
			endif	
			TextPaint(pinx, e.Graphics )
		enddo
		
 		if sr.Peek() >= 0
 			Current_Page = Current_Page + 1
			e.HasMorePages = *true
		else	
			e.HasMorePages = *false	
			sr.Close()
			currentindex = 0
		endif
				
	EndSr
 
Share this answer
 
v2
Microsoft fixed the problem in their latest VS release. Now, when you are in print preview mode and click the printer icon the report prints; just as one would expect it to. So, all is well. Thank you Weberto.
 
Share this answer
 
Thank you deurebokkn. I tried this and I couldn't get it to work but I need to try harder. I'm rushed and am not concentrating as I should. Later today I'm gonna 'get on it'.

I think I'm putting this code in the wrong place. Can you tell me where it goes? Should I click the printDialog control and put it there? Maybe in the click event of a button I place on the form? Any further guidance would be appreciated.

Thanks for your help deurebokkn.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900