Beispiel #1
0
 public static void Dispose()
 {
     try
     {
         wdf.Dispose();
     }
     catch { }
 }
 public static void Close( )
 {
     Cursor.Current = Cursors.Default;
     waiting.Close();
     waiting.Dispose();
 }
Beispiel #3
0
        /// <summary>
        /// 数据表格打印预览
        /// </summary>
        /// <param name="ListGrid">数据表格</param>
        /// <param name="strHead">表头显示信息</param>
        public static void PrintView(DevExpress.XtraGrid.GridControl ListGrid,DevExpress.XtraGrid.Views.Grid.GridView gridView, string strHead)
        {
            Cursor currentCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            //"Report file creating","Read Data, Please waiting..."
            DevExpress.Utils.WaitDialogForm frmWait = new DevExpress.Utils.WaitDialogForm("正在获取数据,请稍候...", "表格报表");
            frmWait.Show();

            //以下以前的一种用法,现在改为可加上表头信息的印方式
            //if (DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable)
            //    DevExpress.XtraPrinting.PrintHelper.ShowPreview(ListGrid);

            //else
            //    //"XtraPrinting Library is not found..."
            //    DevExpress.XtraEditors.XtraMessageBox.Show(common.GetLanguageWord("MESSAGE", "M0028"), "", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //以下为采用新的打印方式
            string middleColumn = strHead;
            string rightColumn = string.Format("打印时间:{0:g}", DateTime.Now);
            PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem());


            PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;

            phf.Header.Content.Clear();
            phf.Header.Font = new Font("宋体", 12, FontStyle.Bold);

            phf.Header.Content.AddRange(new string[] { "打印用户:" + Common._personname, middleColumn, rightColumn });
            phf.Footer.Content.AddRange(new string[] { "", "页次[页 #/#]", "" });

            gridView.OptionsPrint.AutoWidth = false;    //<- 2012-09-18 add

            link.Component = ListGrid;
           


            //link.CreateMarginalHeaderArea += new CreateAreaEventHandler(Link_CreateMarginalHeaderArea);
          
            DevExpress.LookAndFeel.UserLookAndFeel lookfeel = new DevExpress.LookAndFeel.UserLookAndFeel(ListGrid);
            lookfeel.ParentLookAndFeel = ListGrid.LookAndFeel;
            PrintingSystem printSystem = new PrintingSystem();
            PrinterSettingsUsing pst = new PrinterSettingsUsing();
            pst.UseMargins = true;
            pst.UsePaperKind = true;
            printSystem.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.A4;
            printSystem.PageSettings.PaperName = "A4";
            printSystem.PageSettings.LeftMargin = 1;
            printSystem.PageSettings.RightMargin = 1;
            printSystem.PageSettings.Landscape = true;
            printSystem.PageSettings.AssignDefaultPrinterSettings(pst);
            link.PaperKind = printSystem.PageSettings.PaperKind;
            link.Margins = printSystem.PageSettings.Margins;
            link.Landscape = printSystem.PageSettings.Landscape;
            link.CreateDocument();
            link.ShowPreview(lookfeel);

            Cursor.Current = currentCursor;
            frmWait.Dispose();
            frmWait = null;
        }