WPF打印到纸张后想要获得原始的Windows大小/比例

时间:2015-03-26 20:23:28

标签: c# wpf printing

我正在使用此代码进行打印以适合横向打印纸:

            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
        if (printDlg.ShowDialog() == true)
        {
            //get selected printer capabilities
            System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.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.ExtentHeight, capabilities.PageImageableArea.ExtentWidth);

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

            printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

            printButton.Visibility = Visibility.Hidden;
            exitButton.Visibility = Visibility.Hidden;

            //now print the visual to printer to fit on the one page.
            printDlg.PrintVisual(this, "First Fit to Page WPF Print");

我想将Windows恢复为原始大小(全屏)。我该如何做到这一点?

0 个答案:

没有答案