Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: printing VB.NET
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 21-Aug-12 13:58pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you already try it a printdialog where you can select the printer.
 
'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
  Permalink  
Comments
kentuckyjoe at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 534
1 Gihan Liyanage 298
2 RyanDev 260
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 185
0 Sergey Alexandrovich Kryukov 8,936
1 OriginalGriff 7,891
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100