Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to open the print dialog box

thanq
Posted

You can use javascript function window.print(); either on click of the button or on page load.

You can add the following code in page_load function
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(string), "print", "window.print();", true);
 
Share this answer
 
Use it just like any other dialog:
C#
System.Windows.Controls.PrintDialog dialogue = new System.Windows.Controls.PrintDialog();

DialogResult dr = dialogue.ShowDialog();
if( dr == DialogResult.OK)
{
    // Do something
}

dialogue.Dispose();
 
Share this answer
 
Comments
RaviRanjanKr 25-Nov-11 2:12am    
5+
You can use the PrintDialog like this
C#
PrintDocument pd = new PrintDocument();
           pd.PrintPage += new PrintPageEventHandler(PrintPage);
           PrintDialog pdi = new PrintDialog();
           pdi.Document = pd;
           if (pdi.ShowDialog() == DialogResult.OK)
           {
               pd.DocumentName = documentName;
               pd.Print();
           }
           else
           {
              MessageBox.Show("Print Cancelled");
           }


Hope this helps
 
Share this answer
 
Comments
RaviRanjanKr 25-Nov-11 2:13am    
5+
Wayne Gaylard 25-Nov-11 2:28am    
Thanks!
 
Share this answer
 
v2
use this :
C#
// Configure printer dialog box
System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = true;

// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process save file dialog box results 
if (result == true)
{
    // Print document
}</bool>



http://msdn.microsoft.com/en-us/library/aa969773.aspx[^]

http://forums.asp.net/t/1474476.aspx/1[^]

http://www.c-sharpcorner.com/uploadfile/mahesh/printdialog-in-C-Sharp/[^]

how to open print dialog box in my c# application[^]

Thanks,
Ambesha
 
Share this answer
 
you can try this:
PrintDocument item= new PrintDocument();
           item.PrintPage += new PrintPageEventHandler(PrintPage);
           PrintDialog pdi = new PrintDialog();
           pdi.Document = item;
           if (pdi.ShowDialog() == DialogResult.OK)
           {
               item.DocumentName = documentName;
               item.Print();
           }
           else
           {
              MessageBox.Show("Print Cancelled");
           }

thanks hope it helps!
 
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