如何在C#中打印gridview Duplex - devexpress

时间:2017-08-03 17:20:07

标签: c# devexpress

我想在双面打印gridview我尝试了下面显示的代码。但这一行显示错误XtraReport1 r = new XtraReport1();。如何在打印gridView时使其工作? 我得到

  

CS0246:找不到类型或命名空间名称“XtraReport1”。   您是否缺少using指令或程序集引用?

enter image description here

    private void btnPrintPreview_Click(object sender, EventArgs e)
       {
            XtraReport1 r = new XtraReport1();
            r.PrintingSystem.StartPrint += new DevExpress.XtraPrinting.PrintDocumentEventHandler(PrintingSystem_StartPrint);
            r.ShowPreview();
        }

        private void PrintingSystem_StartPrint(object sender, DevExpress.XtraPrinting.PrintDocumentEventArgs e) {
            e.PrintDocument.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Horizontal;
        }

1 个答案:

答案 0 :(得分:0)

浏览文档:
How to: Print a Grid and Show its Print Preview
How to: Customize Print Settings When Printing GridControl
Preset PrinterSettings
Get/Set PageSettings and PrinterSettings to XtraReports reconized by preview and print

  1. 要打印网格控件,您应该使用 GridControl.PrintGridControl.ShowPrintPreview方法。
  2. 然后处理BaseView.PrintInitialize事件以自定义打印设置。
  3. 请参阅此示例,该示例可让您了解如何进行打印事件以进一步自定义:

    public Form1()
    {
        InitializeComponent();
        sqlDataSource1.Fill();
    
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        gridControl1.Print();
    }
    
    private void gridView1_PrintInitialize(object sender, DevExpress.XtraGrid.Views.Base.PrintInitializeEventArgs e)
    {
        PrintingSystemBase pb = e.PrintingSystem as PrintingSystemBase;
        pb.StartPrint -= pb_StartPrint;
        pb.StartPrint +=pb_StartPrint;
    
    
    }
    
    void pb_StartPrint(object sender, PrintDocumentEventArgs e)
    {
        e.PrintDocument.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Horizontal;
        //e.PrintDocument.PrinterSettings.PrintToFile = true;
        e.PrintDocument.PrinterSettings.PrinterName = "Foxit Reader PDF Printer";
    
    }