print preview for mdi child?

ethicalhacker

Well-known member
Joined
Apr 22, 2007
Messages
142
Location
Delhi,India
Programming Experience
5-10
the code
VB.NET:
 PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
doesn't work for me
I have a rich text box on the child form and want to print preview its contents
I use
VB.NET:
Dim child As frmChild = TryCast(Me.ActiveMdiChild, frmChild)
to declare my active mdi child form.
I have put the print preview dialog control on the mdi parent form.
 
I'm a big fan of people saying X "doesn't work". That could mean all sorts of things. ALWAYS explain what DOES happen. There's absolutely nothing wrong with any of the code you've posted in and of itself. You perform the printing in the PrintPage event handler of your PrintDocument. You've made no reference to that so we can't say what the problem might be.
 
Thread moved to Printing forum, please post to appropriate forums, there is often a better option than the General ones.

Here's link to the RichTextBoxEx class everybody's using to get what-you-see print of rich text, Getting WYSIWYG Print Results from a .NET RichTextBox
 
I'm a big fan of people saying X "doesn't work". That could mean all sorts of things. ALWAYS explain what DOES happen. There's absolutely nothing wrong with any of the code you've posted in and of itself. You perform the printing in the PrintPage event handler of your PrintDocument. You've made no reference to that so we can't say what the problem might be.

what exactly happens is it shows a blank print preview
Ive attached a printscreen of the output
 

Attachments

  • runtime.png
    runtime.png
    40.1 KB · Views: 36
VB.NET:
Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
        Dim child As frmChild = TryCast(Me.ActiveMdiChild, frmChild)
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub
 
I have asked you twice now what code is in the PrintPage event handler of your PrintDocument and you have not provided the requested information. You have provided the code that's in the Click event handler of some menu item, but that is not what I asked for and is of no use. Have you even handled the PrintPage event of your PrintDocument? That's where you do the printing so if you haven't then of course nothing gets printed.
 
This is the contents of the Remarks section of the MSDN documentation for the PrintDocument class:
Typically, you create an instance of the PrintDocument class, set the properties that describe how to print, and call the Print method to start the printing process. Handle the PrintPage event where you specify the output to print, by using the Graphics included in the PrintPageEventArgs.
Many of the key words are links to more detailed information too. This is why it's impoprtant to read the documentation for the classes you're using, especially when they don't work as you expect. It will often take you a matter of minutes, or even seconds, to find the information you need.
 
Back
Top