Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the source code for a print button.

the print runs but all that comes out of the printer is a blank page.

how do i fix this so i can print my document?
Thank you

What I have tried:

Private Sub BtnPrint_Click(sender As Object, e As EventArgs) Handles BtnPrint.Click
    PrintDialog1.Document = PrintDocument1

    PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings

    PrintDialog1AllSomePages = True

    If PrintDialog1.ShowDialog = DialogResult.OK Then

    End If

    PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
    PrintDocument1.Print()

End Sub
Posted
Updated 1-Jun-23 2:55am

Unless you have added code to the PrintDocument.PrintPage Event (System.Drawing.Printing) | Microsoft Learn[^] event handler to actually generate output, all you will get is a single blank sheet.

The link includes sample code.
 
Share this answer
 
The Print system does not do the printing for you. Think about it. Where in your code do you have anything that describes what the printed page is supposed to look like? You don't have any!

The Print system exposes a framework for you to write your own code to do the actual printing. On top of the code you posted, you also need to handle the PrintDocument.PrintPage event to draw whatever you need to draw on the "current page". Without that code, the page you get out of the printer will have nothing on it.

See the example at PrintDocument.PrintPage Event (System.Drawing.Printing) | Microsoft Learn[^]
 
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