Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All, I have a button "Print Preview" in my aspx page which i want to use print preview function of IE7,8,9.
I Google and i find some codes but none worked for me, i am using IE9.
the question is how can i call the print preview of IE from my button?
Posted

Neat artcle if you want to use Javascript - Creating print preview page dynamically in ASP.NET[^]
 
Share this answer
 
Comments
Abdul Rahman Hamidy 15-Aug-11 4:27am    
thanks for reply, the link which you mentioned, that link only uses window.print().
that does not work like the IE print preview, I think i should go for ActiveX like code to provide same functionality as IE7,8, and 9.
Hey! Following code might help you out.
C#
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

{

           e.Graphics.DrawString(richTextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 20);

           e.Graphics.PageUnit = GraphicsUnit.Inch;

}



Step2:  write code for printing and print preview.



private void btnPrint_Click(object sender, EventArgs e)

{

            //PrintDialog associate with PrintDocument;

            printDialog1.Document = printDocument1;



            if (printDialog1.ShowDialog()==DialogResult.OK)

            {

                printDocument1.Print();

            }

}



private void btnPrintPreview_Click(object sender, EventArgs e)

{

            //Associate PrintPreviewDialog with PrintDocument.

            printPreviewDialog1.Document = printDocument1;



            // Show PrintPreview Dialog

            printPreviewDialog1.ShowDialog();

}
 
Share this answer
 
Comments
Abdul Rahman Hamidy 15-Aug-11 23:33pm    
thanks for reply, I think this code is for Win form application while I asked for Web forms, anyhow, how can i allow ActiveX in IE7,8 and 9?

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