Пример #1
0
        private void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            Rectangle clip = e.MarginBounds;            //e.PageBounds

            if (pages_printed == 0)
            {
                this.x_res = clip.Width;
                this.y_res = clip.Height;
                fillPagesToPrint();
            }
            PageToPrint ptp = (PageToPrint)pages_to_print[pages_printed];

            e.Graphics.SetClip(clip);
            curr.Paint(e.Graphics, clip, ptp.x, ptp.y);
            e.HasMorePages = ++pages_printed < pages_to_print.Count;
            if (pages_printed == pages_to_print.Count)
            {
                pages_printed = 0;
            }
        }
        /// <summary>
        /// Option change event handler
        /// </summary>
        /// <param name="sender">PrintTaskOptionsDetails object</param>
        /// <param name="args">the event arguments containing the changed option id</param>
        async void printDetailedOptions_OptionChanged(PrintTaskOptionDetails sender, PrintTaskOptionChangedEventArgs args)
        {
            if (args.OptionId == null)
            {
                return;
            }

            string optionId = args.OptionId.ToString();

            // Handle change in Page Range Option
            if (optionId == "PageRange")
            {
                IPrintOptionDetails pageRange = sender.Options[optionId];
                string pageRangeValue         = pageRange.Value.ToString();

                selectionMode = false;

                switch (pageRangeValue)
                {
                case "PrintRange":
                    // Add PageRangeEdit custom option to the option list
                    sender.DisplayedOptions.Add("PageRangeEdit");
                    pageRangeEditVisible = true;
                    await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        ShowContent(null);
                    });

                    break;

                case "PrintSelection":
                    await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        //Scenario4PageRange page = (Scenario4PageRange)scenarioPage;
                        PacketMessaging.Views.FormsPage page = (Scenario4PageRange)scenarioPage;
                        PageToPrint pageContent = (PageToPrint)page.PrintFrame.Content;
                        ShowContent(pageContent.TextContentBlock.SelectedText);
                    });

                    RemovePageRangeEdit(sender);
                    break;

                default:
                    await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        ShowContent(null);
                    });

                    RemovePageRangeEdit(sender);
                    break;
                }

                Refresh();
            }
            else if (optionId == "PageRangeEdit")
            {
                IPrintOptionDetails pageRange = sender.Options[optionId];
                // Expected range format (p1,p2...)*, (p3-p9)* ...
                if (!Regex.IsMatch(pageRange.Value.ToString(), @"^\s*\d+\s*(\-\s*\d+\s*)?(\,\s*\d+\s*(\-\s*\d+\s*)?)*$"))
                {
                    pageRange.ErrorText = "Invalid Page Range (eg: 1-3, 5)";
                }
                else
                {
                    pageRange.ErrorText = string.Empty;
                    try
                    {
                        GetPagesInRange(pageRange.Value.ToString());
                        Refresh();
                    }
                    catch (InvalidPageException ipex)
                    {
                        pageRange.ErrorText = ipex.Message;
                    }
                }
            }
        }