# 打印完毕自动关闭预览脚本 ## 引用 在脚本引用中添加 ``` yy DevExpress.XtraPrinting.v18.1.dll DevExpress.Utils.v18.1.dll ``` ![引用](../images/ReportEndPrint1.png) ## 编写脚本 XtraReport 通过 PrintingSystemBase 基类进行打印,在打印前记录当前 XtraReport ,在打印文件发送到打印机后(EndPrint事件),关闭预览界面。 ```CSharp XtraReport report; private void PrintObject_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { report = (sender as XtraReport); report.PrintingSystem.EndPrint += PrintingSystem_EndPrint; } private void PrintingSystem_EndPrint(object sender, EventArgs e) { report.ClosePreview(); } ``` ![脚本](../images/ReportEndPrint2.png)