Last post Apr 03, 2014 10:43 AM by asif iqbal
Apr 01, 2014 04:33 PM|human2x|LINK
I designed a crystal report and added a button to print the report contents using the following code:
Protected Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
crystalReport.PrintToPrinter(1, True, 0, 0)
this command send the report directly to the printer without showing the Print Dialog Box
I need to show the dialog box so I can select the printer and pages to print. !!!
Please don't provide links to similar subject because I went through many of them but with no result.
Apr 01, 2014 05:04 PM|asif iqbal|LINK
Try the following code
you will have to change the "username" and the "password" with the credentials of your database.
private void Button1_Click(object sender, EventArgs e)
CrystalReport1 report1 = new CrystalReport1();
PrintDialog dialog1 = new PrintDialog();
dialog1.AllowSomePages = true;
dialog1.AllowPrintToFile = false;
if (dialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
int copies = dialog1.PrinterSettings.Copies;
int fromPage = dialog1.PrinterSettings.FromPage;
int toPage = dialog1.PrinterSettings.ToPage;
bool collate = dialog1.PrinterSettings.Collate;
report1.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
report1.PrintToPrinter(copies, collate, fromPage, toPage);
Apr 03, 2014 07:40 AM|Neodynamic|LINK
Are you aware that your code runs on the server side and that it will print the report to some printer available at the server? If you expect to get that code working on the client i.e. that the user can print the displayed report to his local printer, then
it won't work. Now, your code is working on your machine because it is acting like the client & the server i.e. both roles but if you publish your code to an external server, then it won't work. So the question is... do you want to get your report printed
at the server to some printer installed there OR to the client printer? If it's the first one, then just create some page asking the user for num of copies and go ahead with your code. BUT if it is the second option you need, then you can export the report
to PDF and then display it to the user so it can print it "manually" or try using
this code which makes the job a little bit smoothly.
Apr 03, 2014 10:43 AM|asif iqbal|LINK
I hope the solution helped you. Please let us know.