Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

c# - Crystal Report | Printing | Default Printer

I am making one application where user will print invoices which I am displaying using Crystal Report.

The user showed me his current application made using ForPro. In that application, under Printer Options form, one can see all the printers currently installed and the user could select default printer. When the invoice is made, the user presses the print button, then there is one dialog asking for no. of copies. When it's entered, the invoice gets printed directly, without any Print Dialog Box. If the user wants to change the printer again he/she will change it in the Printer Option form.

I want to know if similar thing is possible in Crystal Report and need guidance on how to approach for it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Take a look at the ReportDocument.PrintToPrinter SAP Docs or MSDN Docs for how to specify the PrinterName and then Print using the ReportDocument object.

If you can try and get away from how the FoxPro app UI for printer selection. Instead use the standard print dialog box to select the printer.

You should note that if you don't set the PrinterName before sending the report to the printer it will use the default on the crystal file. Not to be confused with the user's OS default printer.

Here's an example of showing the PrintDialog settings some parameters using the SetParameterValue method and then sending the report document to a printer

// Note: untested
var dialog = new PrintDialog();

Nullable<bool> print = dialog.ShowDialog();
if (print.HasValue && print.Value)
{
    var rd = new ReportDocument();

    rd.Load("ReportFile.rpt");
    rd.SetParameter("Parameter1", "abc");
    rd.SetParameter("Parameter2", "foo");

    rd.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName;
    rd.PrintToPrinter(1, false, 0, 0);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...