예제 #1
0
        protected void PrintCurrentPage(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = (args.Document != null &&
                                args.EditorControl != null &&
                                args.Document.Options.BehaviorOptions.Printable);
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                args.Result = false;
                if (args.Document.Options.BehaviorOptions.Printable == false)
                {
                    // 文档禁止打印
                    return;
                }
                DocumentPrinter printer = new DocumentPrinter(args.Document);
                if (args.EditorControl != null)
                {
                    printer.JumpPrint   = args.EditorControl._JumpPrint;
                    printer.CurrentPage = args.EditorControl.CurrentPage;
                }
                if (args.Parameter is JumpPrintInfo)
                {
                    JumpPrintInfo info = (JumpPrintInfo)args.Parameter;
                    printer.JumpPrint = args.Document.GetJumpPrintInfo(info.Position);
                }
                printer.PrintRange = System.Drawing.Printing.PrintRange.CurrentPage;

                InnerPrint(args, printer, false);
            }
        }
예제 #2
0
        private void InnerPrint(
            WriterCommandEventArgs args,
            DocumentPrinter printer,
            bool refreshDocument)
        {
            System.Windows.Forms.Cursor cur = null;
            JumpPrintInfo infoBack          = null;
            int           piBack            = -1;

            if (args.EditorControl != null)
            {
                infoBack = args.EditorControl._JumpPrint.Clone();
                if (infoBack.Enabled && infoBack.Page != null)
                {
                    piBack = args.EditorControl.Pages.IndexOf(infoBack.Page);
                }

                printer.WriterControl = args.EditorControl;
                cur = args.EditorControl.Cursor;
                args.EditorControl.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                if (refreshDocument)
                {
                    // 冻结用户界面
                    args.EditorControl.FreezeUI();
                }
            }
            try
            {
                args.Result = printer.PrintDocument(args.ShowUI);
            }
            finally
            {
                if (args.EditorControl != null)
                {
                    if (refreshDocument)
                    {
                        args.EditorControl.RefreshDocument();
                        if (piBack >= 0)
                        {
                            infoBack.Page = args.EditorControl.Pages[piBack];
                            args.EditorControl._JumpPrint = infoBack;
                        }
                        args.EditorControl.ReleaseFreezeUI();
                    }
                    args.EditorControl.Cursor = cur;
                }
            }
        }