Click here to Skip to main content
12,630,137 members (25,824 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
i want to open the print dialog box

thanq
Posted 24-Nov-11 20:58pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Use it just like any other dialog:
System.Windows.Controls.PrintDialog dialogue = new System.Windows.Controls.PrintDialog();
 
DialogResult dr = dialogue.ShowDialog();
if( dr == DialogResult.OK)
{
    // Do something
}
 
dialogue.Dispose();
  Permalink  
Comments
RaviRanjankr 25-Nov-11 2:12am
   
5+
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You can use the PrintDialog like this
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
  Permalink  
Comments
RaviRanjankr 25-Nov-11 2:13am
   
5+
Wayne Gaylard 25-Nov-11 2:28am
   
Thanks!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

use this :
// 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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100