Link to home
Start Free TrialLog in
Avatar of kylucky
kylucky

asked on

problem with printer button in print preview - 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. .
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kylucky
kylucky

ASKER

Thank you CC.  My problem is exactly what their problem was.  I did learn from their experience and solution but I'm still not there yet.
 
The way I understand the first person's problem was that he/she was using .dispose in the method.  I am not doing this so .dispose is not the cause of my problem.

On the second thread you referenced they suggested replacing the button and using reflection.  I'm going to study this more because right now I have no idea what reflection is.  I've never used it.  

The third thread suggests a whole new way to solve the problem; the 'coolprintpreviewdialog' method.   He did this in 'C' and I really don't know 'C' so this approach is probably not viable for me.

I have made progress.   Since I was getting page 4 of a three page report I figured I needed to set my page number back to 0 at the end of the preview.   So, when the embedded print button was clicked, and it would go thru the printDocument method it would have the page number correct.   This improved things; no more page 4.   But, it only printed one page.  If the report had 2 pages or 100 pages; I only get page 1.   Now, I will admit, page 1 is better than page 4 of a three page report but it's not there yet.

If you have any other ideas I would appreciate them and in the meantime I'm going to study more closely the second thread you sent and see if I can understand that approach and reflection.   I do know that if I can put my own button on this preview screen then I can definitely make the report print just as I want it to.
Avatar of kylucky

ASKER

I studied the threads you provided CC and none were possible for me.  They would take days and days of study and trying and it just isn't worth it.  I just don't have a week(s) to devote to a print button.   I'm going to close this out.  

I did learn from this.   I learned that what should be a very simple matter; isn't.

And I have one observation.   Can you believe Microsoft would put a print button on a preview form and not have it print out what is being previewed?   There is no logical explanation for this that I can think of.   Every other button on that control does just what it is supposed to do.   But the print button - nothing useful.  They don't program it and they don't even give the developer a way to program it.  What they do offer is an opportunity for smart programmers to see how creative they can be in their attempts to develop a workaround for something Microsoft should have done.  Maybe in VB - 2018 Microsoft will get around to having the print button actually print something.

Thanks for pointing me to these threads CC.
Avatar of kylucky

ASKER

please see my last post.

Thanks.