4 Replies - 6268 Views - Last Post: 18 January 2013 - 11:04 AM Rate Topic: -----

#1 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Creating a Print Preview of a Form

Posted 18 January 2013 - 06:57 AM

Hi all.
I need help please with creating a print PREVIEW of a form and then while looking at the preview there must be a button on the preview to print

the current Coding that i have, does not display any preview:

Dim psd As New PageSetupDialog

        Dim pd As New Printing.PrintDocument

        psd.Document = pd

        If psd.ShowDialog = Windows.Forms.DialogResult.OK Then

            PrintForm1.PrinterSettings = psd.PrinterSettings

            PrintForm1.PrinterSettings.DefaultPageSettings.PaperSize = psd.PrinterSettings.DefaultPageSettings.PaperSize

            If PrintForm1.PrinterSettings.IsValid Then

                PrintForm1.Print()

            End If

        End If

    End Sub



Can someone please help me fix this?

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a Print Preview of a Form

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Creating a Print Preview of a Form

Posted 18 January 2013 - 08:20 AM

Really? None of the numerous posts for print preview in VB helped you at all? Or did you just not look?

http://imgur.com/URX7F

Look at the bottom of this page for MANY other threads on this topic
Was This Post Helpful? 0
  • +
  • -

#3 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Creating a Print Preview of a Form

Posted 18 January 2013 - 09:18 AM

View PosttlhIn`toq, on 18 January 2013 - 08:20 AM, said:

Really? None of the numerous posts for print preview in VB helped you at all? Or did you just not look?

http://imgur.com/URX7F

Look at the bottom of this page for MANY other threads on this topic


I have looked at them, and they don't work either. When I test the program, it closes immediately.

Can you please help me out here.?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Creating a Print Preview of a Form

Posted 18 January 2013 - 09:34 AM

I don't code in VB. I'm a C# guy.
But I have a hard time believing that NONE of the other threads have working print preview code - and that if you followed the example on MSDN that it wouldn't still work.

Speaking of the MSDN example: You don't seem to be following it.
http://msdn.microsof...y/274tyhz7.aspx
They use a PrintPreviewDialog where you use a Printing.PrintDocument



Other considerations:
You have no try/catch construct so if there is an error you crash
Line 13 - if the .IsValid is false you won't print but you don't display or log the error

I think I'd start with the MSDN example.

Quote

When I test the program, it closes immediately.

That's called crashing because you have an error. You need to learn how to debug.

MafiaAndre: What this shows us is that you aren't familiar with breakpoints and how to debug your own code.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Jan 2013
Spoiler



Was This Post Helpful? 0
  • +
  • -

#5 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: Creating a Print Preview of a Form

Posted 18 January 2013 - 11:04 AM

I've tried the MSDN topic, and when I debug my program, and click on the print button, a small gray box comes up, saying "Document does not contain any pages"...

I want my WHOLE form to print, thats why my code I gave at the start, is like it is... I need help correcting the code so I get a preview before I print
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1