这个示例展示了如何以程序方式选择纸张来源,并设置打印机分辨率。

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

C#CopyCode image复制代码
using System;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using System.Drawing.Printing;
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.PrintDialog();
}

private void printingSystem_StartPrint(object sender, PrintDocumentEventArgs e) {
    for (int i = 0; i < e.PrintDocument.PrinterSettings.PaperSources.Count; i++)
        if (e.PrintDocument.PrinterSettings.PaperSources[i].Kind == 
            PaperSourceKind.TractorFeed) {
            e.PrintDocument.DefaultPageSettings.PaperSource = 
                e.PrintDocument.PrinterSettings.PaperSources[i];
            break;
        }

    for (int i = 0; i < e.PrintDocument.PrinterSettings.PrinterResolutions.Count; i++)
        if (e.PrintDocument.PrinterSettings.PrinterResolutions[i].Kind == 
            PrinterResolutionKind.High) {
            e.PrintDocument.DefaultPageSettings.PrinterResolution = 
                e.PrintDocument.PrinterSettings.PrinterResolutions[i];
            break;
        }
}
Visual BasicCopyCode image复制代码
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraPrinting
Imports System.Drawing.Printing
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.PrintDialog()
End Sub

Private Sub printingSystem_StartPrint(ByVal sender As Object, _ 
ByVal e As PrintDocumentEventArgs)
    For i As Integer = 0 To e.PrintDocument.PrinterSettings.PaperSources.Count - 1
        If e.PrintDocument.PrinterSettings.PaperSources(i).Kind = _ 
            PaperSourceKind.TractorFeed Then
            e.PrintDocument.DefaultPageSettings.PaperSource = _ 
                e.PrintDocument.PrinterSettings.PaperSources(i)
            Exit For
        End If
    Next i

    For i As Integer = 0 To e.PrintDocument.PrinterSettings.PrinterResolutions.Count - 1
        If e.PrintDocument.PrinterSettings.PrinterResolutions(i).Kind = _ 
            PrinterResolutionKind.High Then
            e.PrintDocument.DefaultPageSettings.PrinterResolution = _ 
                e.PrintDocument.PrinterSettings.PrinterResolutions(i)
            Exit For
        End If
    Next i
End Sub

CodeCentralShow Me

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

Expand image参阅