当前位置: 首页>>代码示例>>C#>>正文


C# PrintDialog.PrintVisual方法代码示例

本文整理汇总了C#中System.Windows.Controls.PrintDialog.PrintVisual方法的典型用法代码示例。如果您正苦于以下问题:C# PrintDialog.PrintVisual方法的具体用法?C# PrintDialog.PrintVisual怎么用?C# PrintDialog.PrintVisual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.PrintDialog的用法示例。


在下文中一共展示了PrintDialog.PrintVisual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Common.Print(printedPage);
            PrintDialog printDlg = new PrintDialog();

            printDlg.PrintVisual(mygrid, "Grid Printing.");
        }
开发者ID:Ashna,项目名称:ShayanDent,代码行数:7,代码来源:PrintScriiption.xaml.cs

示例2: Print

        public Int32 Print()
        {
            var dlg = new PrintDialog();

            if (dlg.ShowDialog() == true)
            {
                //---FIRST PAGE---//
                // Size the Grid.
                Content.Measure(new Size(Double.PositiveInfinity,
                                         Double.PositiveInfinity));

                Size sizeGrid = Content.DesiredSize;

                //check the width
                if (sizeGrid.Width > dlg.PrintableAreaWidth)
                {
                    MessageBoxResult result = MessageBox.Show("Some Items are out of printable area", "Print",
                                                              MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (result == MessageBoxResult.No)
                        throw new PrintDialogException("print aborted");
                }

                // Position of the grid 
                var ptGrid = new Point(HorizontalOffset, VerticalOffset);

                // Layout of the grid
                Content.Arrange(new Rect(ptGrid, sizeGrid));

                //print
                dlg.PrintVisual(Content, Title);

                //---MULTIPLE PAGES---//

                //---MULTIPLE PAGES---//
                double diff;
                int i = 1;
                while ((diff = sizeGrid.Height - (dlg.PrintableAreaHeight - VerticalOffset*i)*i) > 0)
                {
                    //Position of the grid 
                    var ptSecondGrid = new Point(HorizontalOffset, -sizeGrid.Height + diff + VerticalOffset);

                    // Layout of the grid
                    Content.Arrange(new Rect(ptSecondGrid, sizeGrid));

                    //print
                    int k = i + 1;
                    dlg.PrintVisual(Content, Title + " (Page " + k + ")");

                    i++;
                }

                return i;
            }
            throw new PrintDialogException("print aborted");
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:55,代码来源:UIPrintHelper.cs

示例3: PrintOnClick

        void PrintOnClick(object sender, RoutedEventArgs args)
        {
            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
               //     Create DrawingVisual and open DrawingContext.
                DrawingVisual vis = new DrawingVisual();
                DrawingContext dc = vis.RenderOpen();

                // Draw ellipse.
                dc.DrawEllipse(Brushes.LightGray, new Pen(Brushes.Black, 3),
                               new Point(dlg.PrintableAreaWidth / 2,
                                         dlg.PrintableAreaHeight / 2),
                               dlg.PrintableAreaWidth / 2,
                               dlg.PrintableAreaHeight / 2);

                // Close DrawingContext.
                dc.Close();

                // Finally, print the page.
                dlg.PrintVisual(vis, "My first print job");

            }
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:25,代码来源:PrintEllipse.cs

示例4: PrintDocumentVis

        public void PrintDocumentVis(Bitmap bm, string DocumentName)
        {
            DrawingVisual vis = new DrawingVisual();
            DrawingContext dc = vis.RenderOpen();
            BitmapImage imgSource = new BitmapImage();
            using (MemoryStream memory = new MemoryStream())
            {
                bm.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                imgSource.BeginInit();
                imgSource.StreamSource = memory;
                imgSource.CacheOption = BitmapCacheOption.OnLoad;
                imgSource.EndInit();
            }

            dc.DrawImage(imgSource, new Rect(0, 0, imgSource.Width, imgSource.Height));
            dc.Close();
            PrintDialog pdDialog = new PrintDialog();
            pdDialog.PrintVisual(vis, DocumentName);

            //  Cleanup
            vis = null;
            dc = null;
            imgSource = null;
            pdDialog = null;
        }
开发者ID:JamisonHarris,项目名称:TurboscanNG,代码行数:26,代码来源:PrinterX.cs

示例5: Print

        public static void Print(Grid printedPage)
        {
            PrintDialog dialog = new PrintDialog();

            dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
            dialog.PrintTicket.PageOrientation = PageOrientation.Portrait;
            dialog.PrintTicket.OutputQuality = OutputQuality.High;
            dialog.PrintTicket.PageBorderless = PageBorderless.None;
            dialog.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);

            if (dialog.ShowDialog() == true)
            {
                double pageHeight = printedPage.Height;
                double pageWidth = printedPage.Width;

                printedPage.Height = dialog.PrintableAreaHeight;
                printedPage.Width = dialog.PrintableAreaWidth;

                dialog.PrintVisual(printedPage, "");

                printedPage.Height = pageHeight;
                printedPage.Width = pageWidth;

            }
        }
开发者ID:Ashna,项目名称:ShayanDent,代码行数:25,代码来源:Common.cs

示例6: PrintDialog

        void IUIJob.OnNewOperation(IOperationViewer operationViewer, Operation operation)
        {
            // Only print if we don't have already (verrrrrrrrrrrry helpful during debugging, but also a sanity-check)
            if (CheckIsOperationAlreadyPrinted(operation, true))
            {
                return;
            }

            PrintQueue printQueue = _printQueue.Value;
            // If printing is not possible (an error occurred because the print server is not available etc.).
            if (printQueue == null)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Cannot print job because the configured printer seems not available! Check log entries.");
                return;
            }

            // We need to wait for a bit to let the UI "catch a breath".
            // Otherwise, if printing immediately, it may have side-effects that parts of the visual aren't visible (bindings not updated etc.).
            Thread.Sleep(_configuration.WaitInterval);

            PrintDialog dialog = new PrintDialog();
            dialog.PrintQueue = printQueue;
            dialog.PrintTicket = dialog.PrintQueue.DefaultPrintTicket;
            dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
            dialog.PrintTicket.CopyCount = _configuration.CopyCount;

            FrameworkElement visual = operationViewer.Visual;
            // Measure and arrange the visual before printing otherwise it looks unpredictably weird and may not fit on the page
            visual.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
            visual.Arrange(new Rect(new Point(0, 0), visual.DesiredSize));

            dialog.PrintVisual(visual, "New alarm " + operation.OperationNumber);
        }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:33,代码来源:PrintingUIJob.cs

示例7: PrintPageDialog

        private void PrintPageDialog(Messages.PrintPage printMessage)
        {
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

                //get scale of the print wrt to screen of WPF visual
                double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /  this.ActualHeight);

                //Transform the Visual to scale
                this.LayoutTransform = new ScaleTransform(scale, scale);

                //get the size of the printer page
                Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

                //update the layout of the visual to the printer page size.
                printMessage.Element.Measure(sz);
                printMessage.Element.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

                //now print the visual to printer to fit on the one page.
                printDialog.PrintVisual(printMessage.Element, printMessage.Description);
            }
            
        }
开发者ID:LukeForder,项目名称:TestIt,代码行数:25,代码来源:Shell.xaml.cs

示例8: AskToPrint

        public static void AskToPrint( FrameworkElement ctrl
                                     , string printJobDesc = "Scaled Visual")
        {
            PrintDialog print = new PrintDialog();
            if (print.ShowDialog() != true) return;

            PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket);

            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / ctrl.ActualWidth,
                                    capabilities.PageImageableArea.ExtentHeight / ctrl.ActualHeight);

            //Transform oldTransform = ctrl.LayoutTransform;

            ctrl.LayoutTransform = new ScaleTransform(scale, scale);

            //Size oldSize = new Size(ctrl.ActualWidth, ctrl.ActualHeight);

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            ctrl.Measure(sz);
            ((UIElement)ctrl).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight),
                sz));

            ctrl.Focus();

            print.PrintVisual(ctrl, printJobDesc);
            //ctrl.LayoutTransform = oldTransform;

            //ctrl.Measure(oldSize);

            //((UIElement)ctrl).Arrange(new Rect(new Point(0, 0),
            //    oldSize));
        }
开发者ID:peterson1,项目名称:ErrH,代码行数:32,代码来源:ScaledVisualPrinter.cs

示例9: PrintVisual

        public static void PrintVisual(Grid g)
        {
            printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == false)
                return;
            FrameworkElement e = g as FrameworkElement;
            Transform originalScale = e.LayoutTransform;   
           
            //get selected printer capabilities
            PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
            //get scale of the print wrt to screen of WPF visual
            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / g.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
            g.ActualHeight);
            //Transform the Visual to scale
            g.LayoutTransform = new ScaleTransform(scale, scale);
            //get the size of the printer page

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            //update the layout of the visual to the printer page size.

            g.Measure(sz);
            g.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            //now print the visual to printer to fit on the one page.
           
            printDialog.PrintVisual(g, "Onion Smart Solutions");

            e.LayoutTransform = originalScale;
        }
开发者ID:Stankim,项目名称:Onion,代码行数:29,代码来源:Printing.cs

示例10: AskToPrint

 public static void AskToPrint( ContentPresenter content
                              , string printJobDesc = "Tab Content Visual")
 {
     var dlg = new PrintDialog();
     if (dlg.ShowDialog() != true) return;
     dlg.PrintVisual(content, printJobDesc);
 }
开发者ID:peterson1,项目名称:ErrH,代码行数:7,代码来源:DirectVisualPrinter.cs

示例11: Print

 public void Print()
 {
     PrintDialog dialog = new PrintDialog();
     if (dialog.ShowDialog() == true)
     {
         dialog.PrintVisual(grdMain, "Social Network Analysis");
     }
 }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:8,代码来源:SocialNetworkGraph.xaml.cs

示例12: Button_Click

 private void Button_Click(object sender, RoutedEventArgs e)
 {
     PrintDialog dialog = new PrintDialog();
     if (dialog.ShowDialog() == true)
     {
         dialog.PrintVisual(printArea, "Print Demo");
     }
 }
开发者ID:fjkfjk,项目名称:ExerciseDemo,代码行数:8,代码来源:MainWindow.xaml.cs

示例13: button1_Click

 private void button1_Click(object sender, RoutedEventArgs e)
 {
     PrintDialog printDialog = new PrintDialog();
     if (printDialog.ShowDialog().GetValueOrDefault(false))
     {
         printDialog.PrintVisual(this, this.Title);
     }
 }
开发者ID:sayan801,项目名称:BloodDonationManagement,代码行数:8,代码来源:Testimonial.xaml.cs

示例14: Print_Click

 private void Print_Click(object sender, RoutedEventArgs e)
 {
     var dlg = new PrintDialog();
     if (dlg.ShowDialog().GetValueOrDefault())
     {
         dlg.PrintVisual(view1.Viewport, this.Title);
     }
 }
开发者ID:dermeister0,项目名称:helix-toolkit,代码行数:8,代码来源:MainWindow.xaml.cs

示例15: Print

        public void Print(Visual visual, string description)
        {
            PrintDialog dialog = new PrintDialog();

            if (dialog.ShowDialog().GetValueOrDefault())
            {
                dialog.PrintVisual(visual, description);
            }
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:9,代码来源:Printer.cs


注:本文中的System.Windows.Controls.PrintDialog.PrintVisual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。