本示例演示了如何在代码中指定打印机。

要完成此任务,则把报表实例指派到 ReportPrintTool,并接管 PrintTool.PrintingSystem 打印工具的 PrintingSystemBase.StartPrint 事件。

C#CopyCode image复制代码
using System;
using System.Windows.Forms;
using System.Drawing.Printing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

private void button1_Click(object sender, EventArgs e) {
    ReportPrintTool pt = new ReportPrintTool(new XtraReport1());
    pt.PrintingSystem.StartPrint +=
        new PrintDocumentEventHandler(printingSystem_StartPrint);
    pt.Print();
}

private void printingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
    // Set the printer name.
    e.PrintDocument.PrinterSettings.PrinterName =
        PrinterSettings.InstalledPrinters[0];
}
Visual BasicCopyCode image复制代码
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...

Private Sub button1_Click(ByVal sender As Object, _ 
ByVal e As EventArgs) Handles button1.Click
    Dim pt As New ReportPrintTool(New XtraReport1())
    AddHandler pt.PrintingSystem.StartPrint, AddressOf printingSystem_StartPrint
    pt.Print()
End Sub

Private Sub printingSystem_StartPrint(ByVal sender As Object, _ 
ByVal e As PrintDocumentEventArgs)
    ' Set the printer name.
    e.PrintDocument.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters(0)
End Sub

CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1766。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

Expand image参阅