Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, i need help with coding on how to print a report.
I've got this so far, but when i print, i just print blank pages..
C
private void button1_Click(object sender, EventArgs e)
{
    this.printDialog1.Document = this.printDocument1;
    DialogResult dr = this.printDialog1.ShowDialog();

    string PrintPathe = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    FileToPrint = new System.IO.StreamReader(PrintPathe + @"\Print.txt");
    PrintFont = new System.Drawing.Font("Arial",10);
    printDocument1.Print();



    //printPreviewDialog1.Document = ;
    printDocument1.DocumentName = (PrintPathe + @"\\Print.txt");
    printPreviewDialog1.ShowDialog();

    FileToPrint.Close();

}

Thanx*
Posted
Updated 6-Oct-13 21:50pm
v2
Comments
thatraja 7-Oct-13 4:48am    
Is it related crystal reports?(I saw the Crystal reports Tag in your question)

1 solution

This is because you did not write a single line putting any content in print document. Please read carefully: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

Please see the code sample at the end of this article. It shows how to handle the event PrintPage and use the instance of the class System.Drawing.Graphics to put some graphics on the page. In this example, the line with "ev.Graphics.DrawString" is the only line where some content is put on page, and in your code there is nothing like that at all. No wonder it "prints" blank pages.

—SA
 
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